diff options
author | Shankaranarayanan Puzhavakath Narayanan <snarayanan@research.att.com> | 2018-01-12 04:47:11 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-01-12 04:47:11 +0000 |
commit | bb8471cae394aa6ff0af8ba3e5354f3b121c56fc (patch) | |
tree | 0c5e88589737ffc48671cd17bc4a57acb34570dc | |
parent | c44cd62451fa956f69387115565ce28890b62160 (diff) | |
parent | 75f82ae8c2c81ad372aaf8cf11454ad46149416a (diff) |
Merge "Push policy adapter code (adapted from ECOMP)"
-rw-r--r-- | adapters/policy/__init__.py | 0 | ||||
-rw-r--r-- | adapters/policy/interface.py | 203 | ||||
-rw-r--r-- | adapters/policy/utils.py | 58 | ||||
-rw-r--r-- | models/policy/cmso/xacml/placementPolicies.xcore | 718 | ||||
-rw-r--r-- | models/policy/placement/xacml/placementPolicies.xcore | 728 |
5 files changed, 1707 insertions, 0 deletions
diff --git a/adapters/policy/__init__.py b/adapters/policy/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/adapters/policy/__init__.py diff --git a/adapters/policy/interface.py b/adapters/policy/interface.py new file mode 100644 index 0000000..ee45051 --- /dev/null +++ b/adapters/policy/interface.py @@ -0,0 +1,203 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2015-2017 AT&T Intellectual Property +# +# 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 base64 +import itertools +import json + + +from requests import RequestException +from osdf.operation.exceptions import BusinessException +from osdf.adapters.local_data.local_policies import get_local_policies +from osdf.adapters.policy.utils import _regex_policy_name +from osdf.config.base import osdf_config +from osdf.logging.osdf_logging import audit_log, MH, metrics_log, error_log, debug_log +from osdf.utils.interfaces import RestClient +from osdf.optimizers.placementopt.conductor.api_builder import retrieve_node +from osdf.utils import data_mapping + + +def get_by_name(rest_client, policy_name_list, wildcards=True): + policy_list = [] + for policy_name in policy_name_list: + try: + query_name = policy_name + if wildcards: + query_name = _regex_policy_name(query_name) + policy_list.append(rest_client.request(json={"policyName": query_name})) + except RequestException as err: + audit_log.warn("Error in fetching policy: " + policy_name) + raise BusinessException("Cannot fetch policy {}: ".format(policy_name), err) + return policy_list + + +def get_subscriber_name(req, pmain): + subs_name = retrieve_node(req, pmain['subscriber_name']) + if subs_name is None: + return "DEFAULT" + else: + subs_name_uc = subs_name.upper() + if subs_name_uc in ("DEFAULT", "NULL", ""): + subs_name = "DEFAULT" + return subs_name + + +def get_subscriber_role(rest_client, req, pmain, service_name, scope): + """Make a request to policy and return subscriberRole + :param rest_client: rest client to make call + :param req: request object from MSO + :param pmain: main config that will have policy path information + :param service_name: the type of service to call: e.g. "vCPE + :param scope: the scope of policy to call: e.g. "OOF_HAS_vCPE". + :return: subscriberRole and provStatus retrieved from Subscriber policy + """ + subscriber_role = "DEFAULT" + prov_status = [] + subs_name = get_subscriber_name(req, pmain) + if subs_name == "DEFAULT": + return subscriber_role, prov_status + + policy_subs = pmain['policy_subscriber'] + policy_scope = {"policyName": "{}.*".format(scope), + "configAttributes": { + "serviceType": "{}".format(service_name), + "service": "{}".format(policy_subs)} + } + policy_list = [] + try: + policy_list.append(rest_client.request(json=policy_scope)) + except RequestException as err: + audit_log.warn("Error in fetching policy for {}: ".format(policy_subs)) + return subscriber_role, prov_status + + formatted_policies = [] + for x in itertools.chain(*policy_list): + if x['config'] is None: + raise BusinessException("Config not found for policy with name %s" % x['policyName']) + else: + formatted_policies.append(json.loads(x['config'])) + + for policy in formatted_policies: + property_list = policy['content']['property'] + for prop in property_list: + if subs_name in prop['subscriberName']: + subs_role_list = prop['subscriberRole'] + prov_status = prop['provStatus'] + if isinstance(subs_role_list, list): # as list is returned + return subs_role_list[0], prov_status + return subscriber_role, prov_status + + +def get_by_scope(rest_client, req, config_local, type_service): + policy_list = [] + pmain = config_local['policy_info'][type_service] + pscope = pmain['policy_scope'] + + model_name = retrieve_node(req, pscope['service_name']) + service_name = data_mapping.get_request_service_type(req) + if service_name is None: + service_name = data_mapping.get_service_type(model_name) + scope = pscope['scope_{}'.format(service_name.lower())] + subscriber_role, prov_status = get_subscriber_role(rest_client, req, pmain, service_name, scope) + policy_type_list = pmain['policy_type_{}'.format(service_name.lower())] + for policy_type in policy_type_list: + policy_scope = {"policyName": "{}.*".format(scope), + "configAttributes": { + "serviceType": "{}".format(service_name), + "service": "{}".format(policy_type), + "subscriberRole": "{}".format(subscriber_role)} + } + policy_list.append(rest_client.request(json=policy_scope)) + return policy_list, prov_status + + +def remote_api(req_json, osdf_config, service_type="placement"): + """Make a request to policy and return response -- it accounts for multiple requests that be needed + :param req_json: policy request object (can have multiple policy names) + :param osdf_config: main config that will have credential information + :param service_type: the type of service to call: "placement", "scheduling" + :return: all related policies and provStatus retrieved from Subscriber policy + """ +# if not req_json[service_type + "Info"]['policyId']: +# return [] + + config = osdf_config.deployment + uid, passwd = config['policyPlatformUsername'], config['policyPlatformPassword'] + pcuid, pcpasswd = config['policyClientUsername'], config['policyClientPassword'] + headers = {"ClientAuth": base64.b64encode(bytes("{}:{}".format(pcuid, pcpasswd), "ascii"))} + headers.update({'Environment': config['policyPlatformEnv']}) + url = config['policyPlatformUrl'] + rc = RestClient(userid=uid, passwd=passwd, headers=headers, url=url, log_func=debug_log.debug) + + if osdf_config.core['policy_info'][service_type]['policy_fetch'] == "by_name": + policies = get_by_name(rc, req_json[service_type + "Info"]['policyId'], wildcards=True) + elif osdf_config.core['policy_info'][service_type]['policy_fetch'] == "by_name_no_wildcards": + policies = get_by_name(rc, req_json[service_type + "Info"]['policyId'], wildcards=False) + else: # Get policy by scope + policies, prov_status = get_by_scope(rc, req_json, osdf_config.core, service_type) + + # policies in res are list of lists, so flatten them; also only keep config part + formatted_policies = [] + for x in itertools.chain(*policies): + if x['config'] is None: + raise BusinessException("Config not found for policy with name %s" % x['policyName']) + else: + formatted_policies.append(json.loads(x['config'])) + return formatted_policies, prov_status + + +def local_policies_location(req_json, osdf_config, service_type): + """ + Get folder and list of policy_files if "local policies" option is enabled + :param service_type: placement supported for now, but can be any other service + :return: a tuple (folder, file_list) or None + """ + lp = osdf_config.core.get('osdf_hacks', {}).get('local_policies', {}) + if lp.get('global_disabled'): + return None # short-circuit to disable all local policies + if lp.get('local_{}_policies_enabled'.format(service_type)): + if service_type == "scheduling": + return lp.get('{}_policy_dir'.format(service_type)), lp.get('{}_policy_files'.format(service_type)) + else: + model_name = retrieve_node(req_json, osdf_config.core['policy_info'][service_type]['policy_scope']['service_name']) + service_name = data_mapping.get_service_type(model_name) + return lp.get('{}_policy_dir_{}'.format(service_type, service_name.lower())), lp.get('{}_policy_files_{}'.format(service_type, service_name.lower())) + return None + + +def get_policies(request_json, service_type): + """Validate the request and get relevant policies + :param request_json: Request object + :param service_type: the type of service to call: "placement", "scheduling" + :return: policies associated with this request and provStatus retrieved from Subscriber policy + """ + prov_status = [] + req_info = request_json['requestInfo'] + req_id = req_info['requestId'] + metrics_log.info(MH.requesting("policy", req_id)) + local_info = local_policies_location(request_json, osdf_config, service_type) + + if local_info: # tuple containing location and list of files + to_filter = None + if osdf_config.core['policy_info'][service_type]['policy_fetch'] == "by_name": + to_filter = request_json[service_type + "Info"]['policyId'] + policies = get_local_policies(local_info[0], local_info[1], to_filter) + else: + policies, prov_status= remote_api(request_json, osdf_config, service_type) + + return policies, prov_status diff --git a/adapters/policy/utils.py b/adapters/policy/utils.py new file mode 100644 index 0000000..a006f12 --- /dev/null +++ b/adapters/policy/utils.py @@ -0,0 +1,58 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2015-2017 AT&T Intellectual Property +# +# 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 collections import defaultdict + + +def group_policies(flat_policies): + """Filter policies using the following steps: + 1. Apply prioritization among the policies that are sharing the same policy type and resource type + 2. Remove redundant policies that may applicable across different types of resource + 3. Filter policies based on type and return + :param flat_policies: list of flat policies + :return: Filtered policies + """ + aggregated_policies = {} + filter_policies = defaultdict(list) + policy_name = [] + for policy in flat_policies: + policy_type = policy['content']['type'] + if policy_type not in aggregated_policies: + aggregated_policies[policy_type] = defaultdict(list) + for resource in policy['content']['policyScope']['resourceInstanceType']: + aggregated_policies[policy_type][resource].append(policy) + for policy_type in aggregated_policies: + for resource in aggregated_policies[policy_type]: + if len(aggregated_policies[policy_type][resource]) > 0: + aggregated_policies[policy_type][resource].sort(key=lambda x: x['priority'], reverse=True) + policy = aggregated_policies[policy_type][resource][0] + if policy['policyName'] not in policy_name: + filter_policies[policy['content']['type']].append(policy) + policy_name.append(policy['policyName']) + return filter_policies + + +def _regex_policy_name(policy_name): + """Get the correct policy name as a regex + (e.g. OOF_HAS_vCPE.cloudAttributePolicy ends up in policy as OOF_HAS_vCPE.Config_MS_cloudAttributePolicy.1.xml + So, for now, we query it as OOF_HAS_vCPE..*aicAttributePolicy.*) + :param policy_name: Example: OOF_HAS_vCPE.aicAttributePolicy + :return: regexp for policy: Example: OOF_HAS_vCPE..*aicAttributePolicy.* + """ + p = policy_name.partition('.') + return p[0] + p[1] + ".*" + p[2] + ".*" diff --git a/models/policy/cmso/xacml/placementPolicies.xcore b/models/policy/cmso/xacml/placementPolicies.xcore new file mode 100644 index 0000000..3348cb0 --- /dev/null +++ b/models/policy/cmso/xacml/placementPolicies.xcore @@ -0,0 +1,718 @@ +/* + * This XCORE file contains models for the placement optimization policies in SNIRO. + * @author Ankitkumar Patel + * @version 0.0.1 + * @since 2017-04-13 + */ + +package com.att.ecomp.sniro.policies.placement + +import java.util.UUID + +annotation "http://ecomp.att.com" as ecomp +annotation "http://ecomp.att.com/policy" as policy + +type UUID wraps UUID + +/* + * Comparison operators + */ +enum ComparisonOperator{ + less=1, grater=2, lessEqual=3, greaterEqual=4, equal=5, notEqual=6 +} + +enum TenantType{ + GW_TENANT_ID=1, PORTAL_TENANT_ID=2 +} + +/* + * Computational operators + */ +enum ComputationalOperator{ + sum=1, product=2 +} + + +/* + * Qualifier types + */ +enum Qualifier{ + same=1, different=2 +} + +/* + * Zone category + */ +enum ZoneCategory{ + disaster=1, region=2, complex=3, time=4, maintenance=5 +} + +/* + * Geographical region types + */ +enum GeoRegion{ + US=1, EMEA=2, AP=3, CALA=4, CA=5, INTERNATIONAL=6 +} + +/* + * Parameters + */ +enum Parameter{ + distance=0, latency=1, aic_version=2 + //thoughput=1, geoDistance=1, airDistance=2, latency=3, bandwidth=4 +} + + +/* + * The type of inventory defined in AIC + */ +enum InventoryType{ + service=1, cloud=2 +} + +/* + * The type of AT&T network + */ + enum NetworkType{ + ip=1 + } + +/* + * Objective functions. + */ + +enum ObjectiveFunction{ + minimize=1, maximize=2 +} + +/* + * This is a model of a condition. + * @param parameter This is the parameter of interest. + * @param operator This is a comparison operator. + * @param value This is a value of a parameter + */ +class ConditionalInfo{ + @ecomp(^type = "configuration") + Parameter parameter + @ecomp(^type = "configuration") + ComparisonOperator operator + @ecomp(^type = "configuration") + String value +} + +enum LocationInfo{ + customer_loc=1, none=2, customer_pref_loc=3 +} + + +/* + * Model for distance to location property. + * @param distanceCondition This is a distance condition. + * @param locationInfo This is a location with respect to which distance condition is applied. + */ +class DistanceToLocationProperty{ + //distanceCondition.parameter must be distance. + @ecomp(^type = "configuration") + contains ConditionalInfo distanceCondition + @ecomp(^type = "configuration") + LocationInfo locationInfo +} + +enum DistanceToLocationPolicyType{ + distance_to_location=1 +} + +/* + * Model for distance to location policy. + * @param identity This is an identity created by a user. + * @param type This is the type of a policy. + * @param resourceInstance This is a list of resource instances over which this policy is applied. + * @param distanceToLocationProperty This is the distance properties of the policy. + */ +@policy ( + policyTemplate = "SNIRO-PLACEMENT" +) +class DistanceToLocationPolicy extends SniroPolicyMetaInfo{ + @ecomp(^type = "configuration") + @policy (matching = "true") + DistanceToLocationPolicyType ^type + @ecomp(^type = "configuration") + String[] resourceInstanceType + @ecomp(^type = "configuration") + contains DistanceToLocationProperty distanceToLocationProperty +} + +/* + * The property associated with the NetworkBetweenDemandsPolicy. + * @param latencyCondition The latency property associated with the policy. + * @param locationInfo The customer location information. + */ +class NetworkToLocationProperty{ + //latencyCondition.parameter must be latency. + @ecomp(^type = "configuration") + contains ConditionalInfo latencyCondition + @ecomp(^type = "configuration") + LocationInfo locationInfo +} + +enum NetworkToLocationPolicyType{ + network_to_location=1 +} + +/* + * Network between demands policy. + * @param type The type of a policy. + * @param resourceInstanceType The resources associated with a policy. + * @param networkToLocationProperty The property associated with the policy. + */ + +@policy ( + policyTemplate = "SNIRO-PLACEMENT" +) +class NetworkToLocationPolicy extends SniroPolicyMetaInfo{ + @policy (matching = "true") + @ecomp(^type = "configuration") + NetworkToLocationPolicyType ^type + @ecomp(^type = "configuration") + String[] resourceInstanceType + @ecomp(^type = "configuration") + contains NetworkToLocationProperty networkToLocationProperty +} + +/* + * The property associated with the NetworkBetweenDemandsPolicy. + * @param latencyCondition The latency property associated with the policy. + */ +class NetworkBetweenDemandsProperty{ + //latencyCondition.parameter must be latency. + @ecomp(^type = "configuration") + contains ConditionalInfo latencyCondition +} + +enum NetworkBetweenDemandsPolicyType{ + network_between_demands=1 +} + +/* + * Network between demands policy. + * @param type The type of a policy. + * @param resourceInstanceType The resources associated with a policy. + * @param networkBetweenDemandsProperty The property associated with the policy. + */ +@policy ( + policyTemplate = "SNIRO-PLACEMENT" +) +class NetworkBetweenDemandsPolicy extends SniroPolicyMetaInfo{ + @policy (matching = "true") + @ecomp(^type = "configuration") + NetworkBetweenDemandsPolicyType ^type + @ecomp(^type = "configuration") + String[] resourceInstanceType + @ecomp(^type = "configuration") + contains NetworkBetweenDemandsProperty networkBetweenDemandsProperty +} + + +/* + * Network roles supported a VNF placement + * @param all A list of network roles. + */ +class NetworkRoles{ + @ecomp(^type = "configuration") + String[] all +} + +/* + * Complex names supported by a VNF placement + * @param any A list of complex names. + */ +class Complex{ + @ecomp(^type = "configuration") + String[] any +} +/* + * This are the AIC properties. + * @param aicVersion This is the version of AIC. + * @param aicType This is the type of AIC. + * @param dataPlace This is the type of data plane. + * @param hypervisor This is the type of hypervisor. + * @param networkRoles This is a list of connected networks. + * @param exclusivityGroups This is an exclusivity group Id + * @param state State in which a VNF should be located. + * @param country Country in which a VNF should be located. + * @param getRegion Geographical region in which a VNF should be located. + */ +class AicAttributeProperty{ + //aicVersionCondition.parameter must be aicVersion. + @ecomp(^type = "configuration") + String aicVersion + @ecomp(^type = "configuration") + String aicType + @ecomp(^type = "configuration") + String dataPlane + @ecomp(^type = "configuration") + String hypervisor + @ecomp(^type = "configuration") + contains NetworkRoles networkRoles + @ecomp(^type = "configuration") + contains Complex complex + @ecomp(^type = "configuration") + String exclusivityGroups + @ecomp(^type = "configuration") + String state + @ecomp(^type = "configuration") + String country + @ecomp(^type = "configuration") + GeoRegion geoRegion + @ecomp(^type = "configuration") + String replicationRole + +} + +enum AicAttributePolicyType{ + attribute=1 +} + +/* + * Model for the AIC attribute policy. + * @param type This is the type of a policy. + * @param resourceInstance This is a list of resources over which the policy is applied. + * @param aicAttributeProperty This is the properties associated with the policy. + */ +@policy ( + policyTemplate = "SNIRO-PLACEMENT" +) +class AicAttributePolicy extends SniroPolicyMetaInfo{ + @policy (matching = "true") + @ecomp(^type = "configuration") + AicAttributePolicyType ^type + @ecomp(^type = "configuration") + String[] resourceInstanceType + @ecomp(^type = "configuration") + contains AicAttributeProperty aicAttributeProperty +} + +/* + * The property associated with the capacity policy. + * @param tenant The tenant whose capacity needs to be checked. + * @param description The location of a heat template. + */ +class CapacityProperty{ + @ecomp(^type = "configuration") + TenantType tenant + @ecomp(^type = "configuration") + String description +} + +enum CapacityPolicyType{ + cloud_capacity=1 +} + +/* + * Capacity policy + * @param type The type of a policy. + * @param resourceInstanceType The type of resources associated with a policy. + * @param capacityProperty The property associated with a policy. + */ +@policy ( + policyTemplate = "SNIRO-PLACEMENT" +) +class CapacityPolicy extends SniroPolicyMetaInfo{ + @policy (matching = "true") + @ecomp(^type = "configuration") + CapacityPolicyType ^type + @ecomp(^type = "configuration") + String[] resourceInstanceType + @ecomp(^type = "configuration") + contains CapacityProperty capacityProperty +} + +enum InventoryGroupPolicyType{ + inventory_group = 1 +} + +/* + * Model for the inventory group policy. + * @param type This is the type of a policy. + * @param resourceInstance This is a list of resources that must be grouped/paired + */ +@policy ( + policyTemplate = "SNIRO-PLACEMENT" +) +class InventoryGroupPolicy extends SniroPolicyMetaInfo{ + @policy (matching = "true") + @ecomp(^type = "configuration") + InventoryGroupPolicyType ^type + @ecomp(^type = "configuration") + String[] resourceInstanceType +} + +/* + * This is the property associated with this policy. + * @param controller ECOMP controller. + * @param request This should be key-value pairs to be sent in a request. + */ +class ResourceInstanceProperty{ + @ecomp(^type = "configuration") + String controller + @ecomp(^type = "configuration") + String request +} + +enum ResourceInstancePolicyType{ + instance_fit=1 +} +/* + * Model for the resource instance policy. + * @param type This is the type of a policy. + * @param resourceInstance This is a list of resources. + * @param resourceInstanceProperty This is a property associated with each resource in the list. + */ +@policy ( + policyTemplate = "SNIRO-PLACEMENT" +) +class ResourceInstancePolicy extends SniroPolicyMetaInfo{ + @policy (matching = "true") + @ecomp(^type = "configuration") + ResourceInstancePolicyType ^type + @ecomp(^type = "configuration") + String[] resourceInstanceType + @ecomp(^type = "configuration") + contains ResourceInstanceProperty resourceInstanceProperty + +} + +/* + * This is the property associated with this policy. + * @param controller ECOMP controller + * @param request This should be key-value pairs to be sent in a request. + */ +class ResourceRegionProperty{ + @ecomp(^type = "configuration") + String controller + @ecomp(^type = "configuration") + String request +} + +enum ResourceRegionPolicyType{ + region_fit=1 +} + +/* + * Model for the resource region policy + * @param type This is the type of a policy. + * @param resourceInstance This is a list of resources. + * @param resourceRegionProperty This is a property associated with this policy. + */ +@policy ( + policyTemplate = "SNIRO-PLACEMENT" +) +class ResourceRegionPolicy extends SniroPolicyMetaInfo{ + @policy (matching = "true") + @ecomp(^type = "configuration") + ResourceRegionPolicyType ^type + @ecomp(^type = "configuration") + String[] resourceInstanceType + @ecomp(^type = "configuration") + contains ResourceRegionProperty resourceRegionProperty +} + +/* + * This is the property associated with zone policy. + * @param qualifier This is the qualifier. + * @param category This is the category of a zone. + */ +class ZoneProperty{ + @ecomp(^type = "configuration") + Qualifier qualifier + @ecomp(^type = "configuration") + ZoneCategory category +} + +enum ZonePolicyType{ + zone=1 +} + +/* + * Model of the zone policy. + * @param type This is the type of a policy. + * @param resourceInstanceType This is a list of resources. + * @param zoneProperty This is the property associated with the policy. + */ +@policy ( + policyTemplate = "SNIRO-PLACEMENT" +) + +class ZonePolicy extends SniroPolicyMetaInfo{ + @policy (matching = "true") + @ecomp(^type = "configuration") + ZonePolicyType ^type + @ecomp(^type = "configuration") + String[] resourceInstanceType + @ecomp(^type = "configuration") + contains ZoneProperty zoneProperty +} + +/* + * The property associated with a VNF type. + * @param inventoryProvider The ECOMP entity providing inventory information. + * @param inventoryType The type of an inventory. + * @param serviceId The id of a service. + */ +class VNFPolicyProperty{ + @ecomp(^type = "configuration") + String inventoryProvider + @ecomp(^type = "configuration") + InventoryType inventoryType + @ecomp(^type = "configuration") + contains Attributes attributes +} + +/* + * The property associated with a Subscriber type. + * @param subscriberName The name of a subscriber. + * @param subscriberRole The role of a subscriber. + * @param provStatus The provisioning status of a subscriber. + */ +class SubscriberPolicyProperty{ + @ecomp(^type = "configuration") + String[] subscriberName + @ecomp(^type = "configuration") + String[] subscriberRole + @ecomp(^type = "configuration") + String[] provStatus +} + +enum VNFPolicyType{ + vnfPolicy=1 +} + +enum SubscriberPolicyType{ + subscriberPolicy=1 +} + +class Attributes{ + @ecomp(^type = "configuration") + String globalCustomerId + @ecomp(^type = "configuration") + String operationalStatus + @ecomp(^type = "configuration") + String[] orchestrationStatus + @ecomp(^type = "configuration") + String modelInvariantId + @ecomp(^type = "configuration") + String modelVersionId + @ecomp(^type = "configuration") + String equipmentRole +} + +/* + * Policy associated with a VNF. + * @param resourceInstance This parameter identifies a specific VNF. + * @param inventoryProvider This is the provider of inventory. + * @param inventoryType This is the type of inventory. + * @param serviceType The service associated with a VNF. + * @param serviceId The Id associated with a service. + * @param globalCustomerId The global id of a customer. + */ +@policy ( + policyTemplate = "SNIRO-PLACEMENT" +) +class VNFPolicy extends SniroPolicyMetaInfo{ + @policy (matching = "true") + @ecomp(^type = "configuration") + VNFPolicyType ^type + @ecomp(^type = "configuration") + String[] resourceInstanceType + @ecomp(^type = "configuration") + contains VNFPolicyProperty[] property +} + +/* + * Policy associated with a Subscriber. + * @param subscriberName The name of a subscriber. + * @param subscriberRole The role of a subscriber. + * @param provStatus The provisioning status of a subscriber. + */ +@policy ( + policyTemplate = "SNIRO-PLACEMENT" +) +class SubscriberPolicy extends SniroPolicyMetaInfo{ + @policy (matching = "true") + @ecomp(^type = "configuration") + SubscriberPolicyType ^type + @ecomp(^type = "configuration") + contains SubscriberPolicyProperty[] property +} + + +/* + * This is the property associated with this policy. + * @param providerUrl This is the url of provider to check the capacity. + * @param request This should be key-value pairs to be sent in a request. + */ +class InstanceReservationProperty{ + @ecomp(^type = "configuration") + String controller + @ecomp(^type = "configuration") + String request +} + +enum InstanceReservationPolicyType{ + instance_reservation=1 +} +/* + * Model for the resource instance policy. + * @param identity This is an identity created by a user. + * @param type This is the type of a policy. + * @param resourceInstance This is a list of resources. + * @param resourceInstanceProperty This is a property associated with each resource in the list. + */ +@policy ( + policyTemplate = "SNIRO-PLACEMENT" +) +class instanceReservationPolicy extends SniroPolicyMetaInfo{ + @policy (matching = "true") + @ecomp(^type = "configuration") + InstanceReservationPolicyType ^type + @ecomp(^type = "configuration") + String[] resourceInstanceType + @ecomp(^type = "configuration") + contains InstanceReservationProperty instanceReservationProperty + +} + +/* + * This is a model of an operand. + * @param parameter This is a parameter. + * @param associativity This is a list of entities with which a parameter is associated. + */ + /* +class Operand{ + @ecomp(^type = "configuration") + Parameter parameter + @ecomp(^type = "configuration") + Entity associativity +} +*/ + +/* + * This is the optimization function. + * @param identity This is an identity of a function. + * @param operation This is a computational operator. + * @param leftOperand This is a left operand of a function. + * @param rightOperand This is a right operand of a function. + */ +/* +class OptimizationFunction{ + @ecomp(^type = "configuration") + ExpressionIdentity identity + @ecomp(^type = "configuration") + ComputationalOperator operation + @ecomp(^type = "configuration") + contains Operand[] operands +} +*/ + +/* + * Properties associated with a sub-expression. + * @param weight The weight of an expression. + * @param parameter The parameter involved in an expression. + * @param entity The entities involved in an expression. + * @param operator The operator of an expression. + * @param customerLocationInfo The location of a customer. + */ +class AttributeProperty{ + @ecomp(^type = "configuration") + double weight + @ecomp(^type = "configuration") + Parameter parameter + @ecomp(^type = "configuration") + String[] resource + @ecomp(^type = "configuration") + ComputationalOperator operator + @ecomp(^type = "configuration") + LocationInfo customerLocationInfo +} + +enum PlacementOptimizationPolicyType{ + placementOptimization=1 +} + +/* + * @param operator An operator in an expression. + * @param parameterAttributes Represents sub-expression + */ +class ObjectiveParameter{ + @ecomp(^type = "configuration") + ComputationalOperator operator + @ecomp(^type = "configuration") + contains AttributeProperty[] parameterAttributes +} + +/* + * Model of the placement optimization policy. + * @param type This is the type of a policy. + * @param objective This is an objective function. + * @param objectiveParameter The parameter/expression to be optimized. + */ +@policy ( + policyTemplate = "SNIRO-PLACEMENT" +) + +class PlacementOptimizationPolicy extends SniroPolicyMetaInfo{ + @policy (matching = "true") + @ecomp(^type = "configuration") + PlacementOptimizationPolicyType ^type + @ecomp(^type = "configuration") + ObjectiveFunction objective + @ecomp(^type = "configuration") + contains ObjectiveParameter objectiveParameter +} + + +/* + * Meta information required for SNIRO policies. + * @param identity This is a user-defined identity. + * @param policyScope The scope of a policy + */ + +@policy ( + policyTemplate = "SNIRO" +) +class SniroPolicyMetaInfo{ + @ecomp(^type = "configuration") + String identity + @ecomp(^type = "configuration") + @policy (matching = "true") + contains Scope policyScope +} + +/* + * Scopes in which a policy is applicable. + * @param serviceType The type of a service. + * @param networkType The type of a network + * @param geoRigion The geographical region. + * @param resourceInstanceType The resources associated with a policy/ + * @param subscriberRole + */ +class Scope{ + @ecomp(^type = "configuration") + @policy (matching = "true") + String[] serviceType + @ecomp(^type = "configuration") + @policy (matching = "true") + String[] networkType + @ecomp(^type = "configuration") + @policy (matching = "true") + String[] geoRegion + @ecomp(^type = "configuration") + @policy (matching = "true") + String[] resourceInstanceType + @ecomp(^type = "configuration") + @policy (matching = "true") + String[] modelInvariantId + @ecomp(^type = "configuration") + @policy (matching = "true") + String[] subscriberRole +}
\ No newline at end of file diff --git a/models/policy/placement/xacml/placementPolicies.xcore b/models/policy/placement/xacml/placementPolicies.xcore new file mode 100644 index 0000000..866488e --- /dev/null +++ b/models/policy/placement/xacml/placementPolicies.xcore @@ -0,0 +1,728 @@ +/* + * ================================================================================ + * Copyright (C) 2018 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. +*/ + +package org.onap.oof.osdf.policies.placement + +import java.util.UUID + +annotation "http://org.onap" as onap +annotation "http://org.onap.policy" as policy + +type UUID wraps UUID + +/* + * Comparison operators + */ +enum ComparisonOperator{ + less=1, grater=2, lessEqual=3, greaterEqual=4, equal=5, notEqual=6 +} + +enum TenantType{ + GW_TENANT_ID=1, PORTAL_TENANT_ID=2 +} + +/* + * Computational operators + */ +enum ComputationalOperator{ + sum=1, product=2 +} + + +/* + * Qualifier types + */ +enum Qualifier{ + same=1, different=2 +} + +/* + * Zone category + */ +enum ZoneCategory{ + disaster=1, region=2, complex=3, time=4, maintenance=5 +} + +/* + * Geographical region types + */ +enum GeoRegion{ + US=1, EMEA=2, AP=3, CALA=4, CA=5, INTERNATIONAL=6 +} + +/* + * Parameters + */ +enum Parameter{ + distance=0, latency=1, cloud_version=2 + //thoughput=1, geoDistance=1, airDistance=2, latency=3, bandwidth=4 +} + + +/* + * The type of inventory defined in cloud + */ +enum InventoryType{ + service=1, cloud=2 +} + +/* + * The type of network + */ + enum NetworkType{ + ip=1 + } + +/* + * Objective functions. + */ + +enum ObjectiveFunction{ + minimize=1, maximize=2 +} + +/* + * This is a model of a condition. + * @param parameter This is the parameter of interest. + * @param operator This is a comparison operator. + * @param value This is a value of a parameter + */ +class ConditionalInfo{ + @onap(^type = "configuration") + Parameter parameter + @onap(^type = "configuration") + ComparisonOperator operator + @onap(^type = "configuration") + String value +} + +enum LocationInfo{ + customer_loc=1, none=2, customer_pref_loc=3 +} + + +/* + * Model for distance to location property. + * @param distanceCondition This is a distance condition. + * @param locationInfo This is a location with respect to which distance condition is applied. + */ +class DistanceToLocationProperty{ + //distanceCondition.parameter must be distance. + @onap(^type = "configuration") + contains ConditionalInfo distanceCondition + @onap(^type = "configuration") + LocationInfo locationInfo +} + +enum DistanceToLocationPolicyType{ + distance_to_location=1 +} + +/* + * Model for distance to location policy. + * @param identity This is an identity created by a user. + * @param type This is the type of a policy. + * @param resourceInstance This is a list of resource instances over which this policy is applied. + * @param distanceToLocationProperty This is the distance properties of the policy. + */ +@policy ( + policyTemplate = "OOF-PLACEMENT" +) +class DistanceToLocationPolicy extends OOFPolicyMetaInfo{ + @onap(^type = "configuration") + @policy (matching = "true") + DistanceToLocationPolicyType ^type + @onap(^type = "configuration") + String[] resourceInstanceType + @onap(^type = "configuration") + contains DistanceToLocationProperty distanceToLocationProperty +} + +/* + * The property associated with the NetworkBetweenDemandsPolicy. + * @param latencyCondition The latency property associated with the policy. + * @param locationInfo The customer location information. + */ +class NetworkToLocationProperty{ + //latencyCondition.parameter must be latency. + @onap(^type = "configuration") + contains ConditionalInfo latencyCondition + @onap(^type = "configuration") + LocationInfo locationInfo +} + +enum NetworkToLocationPolicyType{ + network_to_location=1 +} + +/* + * Network between demands policy. + * @param type The type of a policy. + * @param resourceInstanceType The resources associated with a policy. + * @param networkToLocationProperty The property associated with the policy. + */ + +@policy ( + policyTemplate = "OOF-PLACEMENT" +) +class NetworkToLocationPolicy extends OOFPolicyMetaInfo{ + @policy (matching = "true") + @onap(^type = "configuration") + NetworkToLocationPolicyType ^type + @onap(^type = "configuration") + String[] resourceInstanceType + @onap(^type = "configuration") + contains NetworkToLocationProperty networkToLocationProperty +} + +/* + * The property associated with the NetworkBetweenDemandsPolicy. + * @param latencyCondition The latency property associated with the policy. + */ +class NetworkBetweenDemandsProperty{ + //latencyCondition.parameter must be latency. + @onap(^type = "configuration") + contains ConditionalInfo latencyCondition +} + +enum NetworkBetweenDemandsPolicyType{ + network_between_demands=1 +} + +/* + * Network between demands policy. + * @param type The type of a policy. + * @param resourceInstanceType The resources associated with a policy. + * @param networkBetweenDemandsProperty The property associated with the policy. + */ +@policy ( + policyTemplate = "OOF-PLACEMENT" +) +class NetworkBetweenDemandsPolicy extends OOFPolicyMetaInfo{ + @policy (matching = "true") + @onap(^type = "configuration") + NetworkBetweenDemandsPolicyType ^type + @onap(^type = "configuration") + String[] resourceInstanceType + @onap(^type = "configuration") + contains NetworkBetweenDemandsProperty networkBetweenDemandsProperty +} + + +/* + * Network roles supported a VNF placement + * @param all A list of network roles. + */ +class NetworkRoles{ + @onap(^type = "configuration") + String[] all +} + +/* + * Complex names supported by a VNF placement + * @param any A list of complex names. + */ +class Complex{ + @onap(^type = "configuration") + String[] any +} +/* + * This are the cloud properties. + * @param cloudVersion This is the version of cloud. + * @param cloudType This is the type of cloud. + * @param dataPlace This is the type of data plane. + * @param hypervisor This is the type of hypervisor. + * @param networkRoles This is a list of connected networks. + * @param exclusivityGroups This is an exclusivity group Id + * @param state State in which a VNF should be located. + * @param country Country in which a VNF should be located. + * @param getRegion Geographical region in which a VNF should be located. + */ +class cloudAttributeProperty{ + //cloudVersionCondition.parameter must be cloudVersion. + @onap(^type = "configuration") + String cloudVersion + @onap(^type = "configuration") + String cloudType + @onap(^type = "configuration") + String dataPlane + @onap(^type = "configuration") + String hypervisor + @onap(^type = "configuration") + contains NetworkRoles networkRoles + @onap(^type = "configuration") + contains Complex complex + @onap(^type = "configuration") + String exclusivityGroups + @onap(^type = "configuration") + String state + @onap(^type = "configuration") + String country + @onap(^type = "configuration") + GeoRegion geoRegion + @onap(^type = "configuration") + String replicationRole + +} + +enum cloudAttributePolicyType{ + attribute=1 +} + +/* + * Model for the cloud attribute policy. + * @param type This is the type of a policy. + * @param resourceInstance This is a list of resources over which the policy is applied. + * @param cloudAttributeProperty This is the properties associated with the policy. + */ +@policy ( + policyTemplate = "OOF-PLACEMENT" +) +class cloudAttributePolicy extends OOFPolicyMetaInfo{ + @policy (matching = "true") + @onap(^type = "configuration") + cloudAttributePolicyType ^type + @onap(^type = "configuration") + String[] resourceInstanceType + @onap(^type = "configuration") + contains cloudAttributeProperty cloudAttributeProperty +} + +/* + * The property associated with the capacity policy. + * @param tenant The tenant whose capacity needs to be checked. + * @param description The location of a heat template. + */ +class CapacityProperty{ + @onap(^type = "configuration") + TenantType tenant + @onap(^type = "configuration") + String description +} + +enum CapacityPolicyType{ + cloud_capacity=1 +} + +/* + * Capacity policy + * @param type The type of a policy. + * @param resourceInstanceType The type of resources associated with a policy. + * @param capacityProperty The property associated with a policy. + */ +@policy ( + policyTemplate = "OOF-PLACEMENT" +) +class CapacityPolicy extends OOFPolicyMetaInfo{ + @policy (matching = "true") + @onap(^type = "configuration") + CapacityPolicyType ^type + @onap(^type = "configuration") + String[] resourceInstanceType + @onap(^type = "configuration") + contains CapacityProperty capacityProperty +} + +enum InventoryGroupPolicyType{ + inventory_group = 1 +} + +/* + * Model for the inventory group policy. + * @param type This is the type of a policy. + * @param resourceInstance This is a list of resources that must be grouped/paired + */ +@policy ( + policyTemplate = "OOF-PLACEMENT" +) +class InventoryGroupPolicy extends OOFPolicyMetaInfo{ + @policy (matching = "true") + @onap(^type = "configuration") + InventoryGroupPolicyType ^type + @onap(^type = "configuration") + String[] resourceInstanceType +} + +/* + * This is the property associated with this policy. + * @param controller onap controller. + * @param request This should be key-value pairs to be sent in a request. + */ +class ResourceInstanceProperty{ + @onap(^type = "configuration") + String controller + @onap(^type = "configuration") + String request +} + +enum ResourceInstancePolicyType{ + instance_fit=1 +} +/* + * Model for the resource instance policy. + * @param type This is the type of a policy. + * @param resourceInstance This is a list of resources. + * @param resourceInstanceProperty This is a property associated with each resource in the list. + */ +@policy ( + policyTemplate = "OOF-PLACEMENT" +) +class ResourceInstancePolicy extends OOFPolicyMetaInfo{ + @policy (matching = "true") + @onap(^type = "configuration") + ResourceInstancePolicyType ^type + @onap(^type = "configuration") + String[] resourceInstanceType + @onap(^type = "configuration") + contains ResourceInstanceProperty resourceInstanceProperty + +} + +/* + * This is the property associated with this policy. + * @param controller onap controller + * @param request This should be key-value pairs to be sent in a request. + */ +class ResourceRegionProperty{ + @onap(^type = "configuration") + String controller + @onap(^type = "configuration") + String request +} + +enum ResourceRegionPolicyType{ + region_fit=1 +} + +/* + * Model for the resource region policy + * @param type This is the type of a policy. + * @param resourceInstance This is a list of resources. + * @param resourceRegionProperty This is a property associated with this policy. + */ +@policy ( + policyTemplate = "OOF-PLACEMENT" +) +class ResourceRegionPolicy extends OOFPolicyMetaInfo{ + @policy (matching = "true") + @onap(^type = "configuration") + ResourceRegionPolicyType ^type + @onap(^type = "configuration") + String[] resourceInstanceType + @onap(^type = "configuration") + contains ResourceRegionProperty resourceRegionProperty +} + +/* + * This is the property associated with zone policy. + * @param qualifier This is the qualifier. + * @param category This is the category of a zone. + */ +class ZoneProperty{ + @onap(^type = "configuration") + Qualifier qualifier + @onap(^type = "configuration") + ZoneCategory category +} + +enum ZonePolicyType{ + zone=1 +} + +/* + * Model of the zone policy. + * @param type This is the type of a policy. + * @param resourceInstanceType This is a list of resources. + * @param zoneProperty This is the property associated with the policy. + */ +@policy ( + policyTemplate = "OOF-PLACEMENT" +) + +class ZonePolicy extends OOFPolicyMetaInfo{ + @policy (matching = "true") + @onap(^type = "configuration") + ZonePolicyType ^type + @onap(^type = "configuration") + String[] resourceInstanceType + @onap(^type = "configuration") + contains ZoneProperty zoneProperty +} + +/* + * The property associated with a VNF type. + * @param inventoryProvider The onap entity providing inventory information. + * @param inventoryType The type of an inventory. + * @param serviceId The id of a service. + */ +class VNFPolicyProperty{ + @onap(^type = "configuration") + String inventoryProvider + @onap(^type = "configuration") + InventoryType inventoryType + @onap(^type = "configuration") + contains Attributes attributes +} + +/* + * The property associated with a Subscriber type. + * @param subscriberName The name of a subscriber. + * @param subscriberRole The role of a subscriber. + * @param provStatus The provisioning status of a subscriber. + */ +class SubscriberPolicyProperty{ + @onap(^type = "configuration") + String[] subscriberName + @onap(^type = "configuration") + String[] subscriberRole + @onap(^type = "configuration") + String[] provStatus +} + +enum VNFPolicyType{ + vnfPolicy=1 +} + +enum SubscriberPolicyType{ + subscriberPolicy=1 +} + +class Attributes{ + @onap(^type = "configuration") + String globalCustomerId + @onap(^type = "configuration") + String operationalStatus + @onap(^type = "configuration") + String[] orchestrationStatus + @onap(^type = "configuration") + String modelInvariantId + @onap(^type = "configuration") + String modelVersionId + @onap(^type = "configuration") + String equipmentRole +} + +/* + * Policy associated with a VNF. + * @param resourceInstance This parameter identifies a specific VNF. + * @param inventoryProvider This is the provider of inventory. + * @param inventoryType This is the type of inventory. + * @param serviceType The service associated with a VNF. + * @param serviceId The Id associated with a service. + * @param globalCustomerId The global id of a customer. + */ +@policy ( + policyTemplate = "OOF-PLACEMENT" +) +class VNFPolicy extends OOFPolicyMetaInfo{ + @policy (matching = "true") + @onap(^type = "configuration") + VNFPolicyType ^type + @onap(^type = "configuration") + String[] resourceInstanceType + @onap(^type = "configuration") + contains VNFPolicyProperty[] property +} + +/* + * Policy associated with a Subscriber. + * @param subscriberName The name of a subscriber. + * @param subscriberRole The role of a subscriber. + * @param provStatus The provisioning status of a subscriber. + */ +@policy ( + policyTemplate = "OOF-PLACEMENT" +) +class SubscriberPolicy extends OOFPolicyMetaInfo{ + @policy (matching = "true") + @onap(^type = "configuration") + SubscriberPolicyType ^type + @onap(^type = "configuration") + contains SubscriberPolicyProperty[] property +} + + +/* + * This is the property associated with this policy. + * @param providerUrl This is the url of provider to check the capacity. + * @param request This should be key-value pairs to be sent in a request. + */ +class InstanceReservationProperty{ + @onap(^type = "configuration") + String controller + @onap(^type = "configuration") + String request +} + +enum InstanceReservationPolicyType{ + instance_reservation=1 +} +/* + * Model for the resource instance policy. + * @param identity This is an identity created by a user. + * @param type This is the type of a policy. + * @param resourceInstance This is a list of resources. + * @param resourceInstanceProperty This is a property associated with each resource in the list. + */ +@policy ( + policyTemplate = "OOF-PLACEMENT" +) +class InstanceReservationPolicy extends OOFPolicyMetaInfo{ + @policy (matching = "true") + @onap(^type = "configuration") + InstanceReservationPolicyType ^type + @onap(^type = "configuration") + String[] resourceInstanceType + @onap(^type = "configuration") + contains InstanceReservationProperty instanceReservationProperty + +} + +/* + * This is a model of an operand. + * @param parameter This is a parameter. + * @param associativity This is a list of entities with which a parameter is associated. + */ + /* +class Operand{ + @onap(^type = "configuration") + Parameter parameter + @onap(^type = "configuration") + Entity associativity +} +*/ + +/* + * This is the optimization function. + * @param identity This is an identity of a function. + * @param operation This is a computational operator. + * @param leftOperand This is a left operand of a function. + * @param rightOperand This is a right operand of a function. + */ +/* +class OptimizationFunction{ + @onap(^type = "configuration") + ExpressionIdentity identity + @onap(^type = "configuration") + ComputationalOperator operation + @onap(^type = "configuration") + contains Operand[] operands +} +*/ + +/* + * Properties associated with a sub-expression. + * @param weight The weight of an expression. + * @param parameter The parameter involved in an expression. + * @param entity The entities involved in an expression. + * @param operator The operator of an expression. + * @param customerLocationInfo The location of a customer. + */ +class AttributeProperty{ + @onap(^type = "configuration") + double weight + @onap(^type = "configuration") + Parameter parameter + @onap(^type = "configuration") + String[] resource + @onap(^type = "configuration") + ComputationalOperator operator + @onap(^type = "configuration") + LocationInfo customerLocationInfo +} + +enum PlacementOptimizationPolicyType{ + placementOptimization=1 +} + +/* + * @param operator An operator in an expression. + * @param parameterAttributes Represents sub-expression + */ +class ObjectiveParameter{ + @onap(^type = "configuration") + ComputationalOperator operator + @onap(^type = "configuration") + contains AttributeProperty[] parameterAttributes +} + +/* + * Model of the placement optimization policy. + * @param type This is the type of a policy. + * @param objective This is an objective function. + * @param objectiveParameter The parameter/expression to be optimized. + */ +@policy ( + policyTemplate = "OOF-PLACEMENT" +) + +class PlacementOptimizationPolicy extends OOFPolicyMetaInfo{ + @policy (matching = "true") + @onap(^type = "configuration") + PlacementOptimizationPolicyType ^type + @onap(^type = "configuration") + ObjectiveFunction objective + @onap(^type = "configuration") + contains ObjectiveParameter objectiveParameter +} + + +/* + * Meta information required for oof policies. + * @param identity This is a user-defined identity. + * @param policyScope The scope of a policy + */ + +@policy ( + policyTemplate = "OOF-PLACEMENT" +) +class OOFPolicyMetaInfo{ + @onap(^type = "configuration") + String identity + @onap(^type = "configuration") + @policy (matching = "true") + contains Scope policyScope +} + +/* + * Scopes in which a policy is applicable. + * @param serviceType The type of a service. + * @param networkType The type of a network + * @param geoRigion The geographical region. + * @param resourceInstanceType The resources associated with a policy/ + * @param subscriberRole + */ +class Scope{ + @onap(^type = "configuration") + @policy (matching = "true") + String[] serviceType + @onap(^type = "configuration") + @policy (matching = "true") + String[] networkType + @onap(^type = "configuration") + @policy (matching = "true") + String[] geoRegion + @onap(^type = "configuration") + @policy (matching = "true") + String[] resourceInstanceType + @onap(^type = "configuration") + @policy (matching = "true") + String[] modelInvariantId + @onap(^type = "configuration") + @policy (matching = "true") + String[] subscriberRole +} |