Merge "Added one typeless Policy in MockPolicyAgent"
diff --git a/.gitignore b/.gitignore
index 1557d03..f459dca 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@
.sts4-cache
.project
.settings
+.pydevproject
\ No newline at end of file
diff --git a/sdnc-a1-controller/northbound/features/features-sdnc-a1-northbound/pom.xml b/sdnc-a1-controller/northbound/features/features-sdnc-a1-northbound/pom.xml
index 49737bf..e16ed98 100644
--- a/sdnc-a1-controller/northbound/features/features-sdnc-a1-northbound/pom.xml
+++ b/sdnc-a1-controller/northbound/features/features-sdnc-a1-northbound/pom.xml
@@ -13,7 +13,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>feature-repo-parent</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
<relativePath/>
</parent>
diff --git a/sdnc-a1-controller/northbound/features/installer/pom.xml b/sdnc-a1-controller/northbound/features/installer/pom.xml
index d2e7dcc..c8a35b0 100755
--- a/sdnc-a1-controller/northbound/features/installer/pom.xml
+++ b/sdnc-a1-controller/northbound/features/installer/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
<relativePath/>
</parent>
diff --git a/sdnc-a1-controller/northbound/features/pom.xml b/sdnc-a1-controller/northbound/features/pom.xml
index 43302a5..b68d283 100755
--- a/sdnc-a1-controller/northbound/features/pom.xml
+++ b/sdnc-a1-controller/northbound/features/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
<relativePath/>
</parent>
diff --git a/sdnc-a1-controller/northbound/features/sdnc-a1-northbound-all/pom.xml b/sdnc-a1-controller/northbound/features/sdnc-a1-northbound-all/pom.xml
index b9a8332..265f576 100644
--- a/sdnc-a1-controller/northbound/features/sdnc-a1-northbound-all/pom.xml
+++ b/sdnc-a1-controller/northbound/features/sdnc-a1-northbound-all/pom.xml
@@ -13,7 +13,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>single-feature-parent</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
<relativePath/>
</parent>
diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/features/features-nonrt-ric-api/pom.xml b/sdnc-a1-controller/northbound/nonrt-ric-api/features/features-nonrt-ric-api/pom.xml
index 10b5d43..6935b62 100644
--- a/sdnc-a1-controller/northbound/nonrt-ric-api/features/features-nonrt-ric-api/pom.xml
+++ b/sdnc-a1-controller/northbound/nonrt-ric-api/features/features-nonrt-ric-api/pom.xml
@@ -24,7 +24,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>feature-repo-parent</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
<relativePath/>
</parent>
diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/features/pom.xml b/sdnc-a1-controller/northbound/nonrt-ric-api/features/pom.xml
index a83de20..59a108f 100644
--- a/sdnc-a1-controller/northbound/nonrt-ric-api/features/pom.xml
+++ b/sdnc-a1-controller/northbound/nonrt-ric-api/features/pom.xml
@@ -24,7 +24,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
<relativePath/>
</parent>
diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/features/sdnc-nonrt-ric-api/pom.xml b/sdnc-a1-controller/northbound/nonrt-ric-api/features/sdnc-nonrt-ric-api/pom.xml
index f39d9ca..4da7a69 100644
--- a/sdnc-a1-controller/northbound/nonrt-ric-api/features/sdnc-nonrt-ric-api/pom.xml
+++ b/sdnc-a1-controller/northbound/nonrt-ric-api/features/sdnc-nonrt-ric-api/pom.xml
@@ -24,7 +24,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>single-feature-parent</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
<relativePath/>
</parent>
diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/installer/pom.xml b/sdnc-a1-controller/northbound/nonrt-ric-api/installer/pom.xml
index 2532d11..e17a79b 100755
--- a/sdnc-a1-controller/northbound/nonrt-ric-api/installer/pom.xml
+++ b/sdnc-a1-controller/northbound/nonrt-ric-api/installer/pom.xml
@@ -24,7 +24,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
<relativePath/>
</parent>
diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/model/pom.xml b/sdnc-a1-controller/northbound/nonrt-ric-api/model/pom.xml
index 7d45eb5..1a686a3 100644
--- a/sdnc-a1-controller/northbound/nonrt-ric-api/model/pom.xml
+++ b/sdnc-a1-controller/northbound/nonrt-ric-api/model/pom.xml
@@ -32,7 +32,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>binding-parent</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
<relativePath/>
</parent>
diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/pom.xml b/sdnc-a1-controller/northbound/nonrt-ric-api/pom.xml
index 2868a0c..d0bacb0 100644
--- a/sdnc-a1-controller/northbound/nonrt-ric-api/pom.xml
+++ b/sdnc-a1-controller/northbound/nonrt-ric-api/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
<relativePath />
</parent>
diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/pom.xml b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/pom.xml
index 02e32e7..2a586ba 100644
--- a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/pom.xml
+++ b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/pom.xml
@@ -34,7 +34,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>binding-parent</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
<relativePath/>
</parent>
diff --git a/sdnc-a1-controller/northbound/pom.xml b/sdnc-a1-controller/northbound/pom.xml
index 6e0878c..e6727c3 100644
--- a/sdnc-a1-controller/northbound/pom.xml
+++ b/sdnc-a1-controller/northbound/pom.xml
@@ -32,7 +32,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
<relativePath/>
</parent>
diff --git a/sdnc-a1-controller/oam/installation/pom.xml b/sdnc-a1-controller/oam/installation/pom.xml
index 0b64bca..1a2cc09 100644
--- a/sdnc-a1-controller/oam/installation/pom.xml
+++ b/sdnc-a1-controller/oam/installation/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
diff --git a/sdnc-a1-controller/oam/installation/sdnc-a1/pom.xml b/sdnc-a1-controller/oam/installation/sdnc-a1/pom.xml
index 3e0b468..27c89f7 100644
--- a/sdnc-a1-controller/oam/installation/sdnc-a1/pom.xml
+++ b/sdnc-a1-controller/oam/installation/sdnc-a1/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -41,7 +41,7 @@
<sdnc.project.version>${project.version}</sdnc.project.version>
<sdnc.build.timestamp>${maven.build.timestamp}</sdnc.build.timestamp>
<sdnc.northbound.version>1.7.3-SNAPSHOT</sdnc.northbound.version>
- <ccsdk.docker.version>0.6.3</ccsdk.docker.version>
+ <ccsdk.docker.version>0.7.0</ccsdk.docker.version>
<docker.push.phase>deploy</docker.push.phase>
</properties>
diff --git a/sdnc-a1-controller/oam/platform-logic/installer/pom.xml b/sdnc-a1-controller/oam/platform-logic/installer/pom.xml
index 77fb72c..99df343 100644
--- a/sdnc-a1-controller/oam/platform-logic/installer/pom.xml
+++ b/sdnc-a1-controller/oam/platform-logic/installer/pom.xml
@@ -24,7 +24,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
<relativePath/>
</parent>
diff --git a/sdnc-a1-controller/oam/platform-logic/pom.xml b/sdnc-a1-controller/oam/platform-logic/pom.xml
index c4f3e8f..8589699 100644
--- a/sdnc-a1-controller/oam/platform-logic/pom.xml
+++ b/sdnc-a1-controller/oam/platform-logic/pom.xml
@@ -24,7 +24,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
<relativePath/>
</parent>
diff --git a/sdnc-a1-controller/oam/platform-logic/setup/pom.xml b/sdnc-a1-controller/oam/platform-logic/setup/pom.xml
index 4b8b354..8c5f5cd 100644
--- a/sdnc-a1-controller/oam/platform-logic/setup/pom.xml
+++ b/sdnc-a1-controller/oam/platform-logic/setup/pom.xml
@@ -24,7 +24,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
<relativePath/>
</parent>
@@ -55,7 +55,7 @@
<artifactItem>
<groupId>org.onap.ccsdk.distribution</groupId>
<artifactId>platform-logic-installer</artifactId>
- <version>${ccsdk.distribution.version}</version>
+ <version>0.7.1</version>
<type>zip</type>
<overWrite>true</overWrite>
<outputDirectory>../target</outputDirectory>
diff --git a/sdnc-a1-controller/oam/pom.xml b/sdnc-a1-controller/oam/pom.xml
index 8cc1cab..14c7ce6 100755
--- a/sdnc-a1-controller/oam/pom.xml
+++ b/sdnc-a1-controller/oam/pom.xml
@@ -24,7 +24,7 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>1.4.3</version>
+ <version>1.5.1</version>
</parent>
<groupId>org.o-ran-sc.nonrtric.sdnc-a1.oam</groupId>
diff --git a/test/usecases/healthcheck/src/main.py b/test/usecases/healthcheck/src/main.py
new file mode 100644
index 0000000..d3fed3a
--- /dev/null
+++ b/test/usecases/healthcheck/src/main.py
@@ -0,0 +1,261 @@
+# ============LICENSE_START===============================================
+# Copyright (C) 2020 Nordix Foundation. 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=================================================
+#
+
+import argparse
+from datetime import datetime
+from pygments.util import xrange
+from requests import ConnectionError
+import requests
+import sys
+import threading
+import time
+
+SERVICE_NAME = 'HealthCheck'
+BASE_URL = 'http://localhost:8081'
+RIC_CHUNK_SIZE = 10
+TIME_BETWEEN_CHECKS = 60
+
+type_to_use = ''
+policy_body = ''
+
+
+class Ric:
+
+ def __init__(self, name, supported_types, state):
+ self.name = name
+ self.supports_type_to_use = self.policy_type_supported(supported_types)
+ self.state = state
+ self.no_of_created_policies = 0
+ self.no_of_read_policies = 0
+ self.no_of_updated_policies = 0
+ self.no_of_deleted_policies = 0
+
+ def update_supported_types(self, supported_types):
+ self.supports_type_to_use = self.policy_type_supported(supported_types)
+
+ def policy_type_supported(self, supported_policy_types):
+ for supported_type in supported_policy_types:
+ if type_to_use == supported_type:
+ return True
+
+ return False
+
+
+class PolicyCheckThread (threading.Thread):
+
+ def __init__(self, thread_id, ric):
+ threading.Thread.__init__(self)
+ self.thread_id = thread_id
+ self.ric = ric
+
+ def run(self):
+ verboseprint(f'Checking ric: {self.ric.name}')
+ if put_policy(self.thread_id, self.ric.name):
+ verboseprint(f'Created policy: {self.thread_id} in ric: {self.ric.name}')
+ self.ric.no_of_created_policies += 1
+ time.sleep(0.5)
+ if get_policy(self.thread_id):
+ verboseprint(f'Read policy: {self.thread_id} from ric: {self.ric.name}')
+ self.ric.no_of_read_policies += 1
+ if put_policy(self.thread_id, self.ric.name, update_value=1):
+ verboseprint(f'Updated policy: {self.thread_id} in ric: {self.ric.name}')
+ self.ric.no_of_updated_policies += 1
+ if delete_policy(self.thread_id):
+ verboseprint(f'Deleted policy: {self.thread_id} from ric: {self.ric.name}')
+ self.ric.no_of_deleted_policies += 1
+
+
+def get_rics_from_agent():
+ resp = requests.get(BASE_URL + '/rics')
+ if not resp.ok:
+ verboseprint(f'Unable to get Rics {resp.status_code}')
+ return {}
+ return resp.json()
+
+
+def create_ric_dict(rics_as_json):
+ rics = {}
+ for ric_info in rics_as_json:
+ rics[ric_info["ricName"]] = (Ric(ric_info["ricName"], ric_info["policyTypes"], ric_info['state']))
+ verboseprint(f'Adding ric: {rics[ric_info["ricName"]]}')
+
+ return rics
+
+
+def update_rics():
+ added_rics = {}
+ for ric_info in get_rics_from_agent():
+ if ric_info["ricName"] in rics:
+ rics[ric_info["ricName"]].update_supported_types(ric_info["policyTypes"])
+ rics[ric_info["ricName"]].state = ric_info['state']
+ else:
+ added_rics[ric_info["ricName"]] = (Ric(ric_info["ricName"], ric_info["policyTypes"]))
+ verboseprint(f'Adding ric: {rics[ric_info["ricName"]]}')
+
+ rics.update(added_rics)
+
+
+def put_policy(thread_id, ric_name, update_value=0):
+ policy_id = f'thread_{thread_id}'
+ complete_url = f'{BASE_URL}/policy?type={type_to_use}&id={policy_id}&ric={ric_name}&service={SERVICE_NAME}'
+ headers = {'content-type': 'application/json'}
+ resp = requests.put(complete_url, policy_body.replace('XXX', str(thread_id + update_value)), headers=headers, verify=False)
+
+ if not resp.ok:
+ verboseprint(f'Unable to create policy {resp}')
+ return False
+ else:
+ return True
+
+
+def get_policy(thread_id):
+ policy_id = f'thread_{thread_id}'
+ complete_url = f'{BASE_URL}/policy?id={policy_id}'
+ resp = requests.get(complete_url)
+
+ if not resp.ok:
+ verboseprint(f'Unable to get policy {resp}')
+ return False
+ else:
+ return True
+
+
+def delete_policy(thread_id):
+ policy_id = f'thread_{thread_id}'
+ complete_url = f'{BASE_URL}/policy?id={policy_id}'
+ resp = requests.delete(complete_url)
+
+ if not resp.ok:
+ verboseprint(f'Unable to delete policy for policy ID {policy_id}')
+ return False
+
+ return True
+
+
+def statistics(duration):
+ no_of_unavailable_rics = 0
+ no_of_rics_not_supporting_type = 0
+ no_of_rics_supporting_type = 0
+ no_of_created_policies = 0
+ no_of_read_policies = 0
+ no_of_updated_policies = 0
+ no_of_deleted_policies = 0
+
+ for ric in rics.values():
+ if not (ric.state == 'AVAILABLE' or ric.state == 'CONSISTENCY_CHECK'):
+ no_of_unavailable_rics += 1
+ elif ric.supports_type_to_use:
+ no_of_rics_supporting_type += 1
+ no_of_created_policies += ric.no_of_created_policies
+ no_of_read_policies += ric.no_of_read_policies
+ no_of_updated_policies += ric.no_of_updated_policies
+ no_of_deleted_policies += ric.no_of_deleted_policies
+ else:
+ no_of_rics_not_supporting_type += 1
+
+ print(f'*********** Statistics {datetime.now().strftime("%Y-%m-%d %H:%M:%S")} ***********')
+ print(f'Duration of check: {duration.total_seconds()} seconds')
+ print(f'Number of checks: {no_of_checks}')
+ print(f'Number of unavailable rics: {no_of_unavailable_rics}')
+ print(f'Number of rics not supporting type: {no_of_rics_not_supporting_type}')
+ print(f'Number of rics supporting type: {no_of_rics_supporting_type}')
+ print(f'Number of created policies: {no_of_created_policies}')
+ print(f'Number of read policies: {no_of_read_policies}')
+ print(f'Number of updated policies: {no_of_updated_policies}')
+ print(f'Number of deleted policies: {no_of_deleted_policies}')
+ print('******************************************************')
+
+
+def run_check_threads(rics):
+ thread_id = 1
+ threads = []
+ for ric in rics.values():
+ if ric.supports_type_to_use and (ric.state == 'AVAILABLE' or ric.state == 'CONSISTENCY_CHECK'): #or ric.name == 'ric_not_working':
+ policy_checker = PolicyCheckThread(thread_id, ric)
+ policy_checker.start()
+ thread_id += 1
+ threads.append(policy_checker)
+
+ for checker in threads:
+ checker.join()
+
+
+def split_rics_equally(chunks):
+ # prep with empty dicts
+ return_list = [dict() for _ in xrange(chunks)]
+ idx = 0
+ for k,v in rics.items():
+ return_list[idx][k] = v
+ if idx < chunks-1: # indexes start at 0
+ idx += 1
+ else:
+ idx = 0
+ return return_list
+
+
+def get_no_of_chunks(size_of_chunks, size_to_chunk):
+ (q, _) = divmod(size_to_chunk, size_of_chunks)
+ return q
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(prog='PROG')
+ parser.add_argument('policyTypeId', help='The ID of the policy type to use')
+ parser.add_argument('policyBodyPath', help='The path to the JSON body of the policy to create')
+ parser.add_argument('-v', '--verbose', action='store_true', help='Turn on verbose printing')
+ parser.add_argument('--version', action='version', version='%(prog)s 1.0')
+ args = vars(parser.parse_args())
+
+ if args['verbose']:
+ def verboseprint(*args, **kwargs):
+ print(*args, **kwargs)
+ else:
+ verboseprint = lambda *a, **k: None # do-nothing function
+
+ verboseprint(f'Using policy type {args["policyTypeId"]}')
+ verboseprint(f'Using policy file {args["policyBodyPath"]}')
+
+ type_to_use = args["policyTypeId"]
+ with open(args["policyBodyPath"]) as json_file:
+ policy_body = json_file.read()
+ verboseprint(f'Policy body: {policy_body}')
+
+ try:
+ rics_from_agent = get_rics_from_agent()
+ except ConnectionError:
+ print(f'Policy Agent is not answering on {BASE_URL}, cannot start!')
+ sys.exit(1)
+
+ rics = create_ric_dict(rics_from_agent)
+
+ no_of_checks = 0
+ while True:
+ start_time = datetime.now()
+ chunked_rics = split_rics_equally(get_no_of_chunks(RIC_CHUNK_SIZE, rics.__len__()))
+ for ric_chunk in chunked_rics:
+ run_check_threads(ric_chunk)
+
+ no_of_checks += 1
+ finish_time = datetime.now()
+ duration = finish_time - start_time
+ statistics(duration)
+ sleep_time = TIME_BETWEEN_CHECKS - duration.total_seconds()
+ verboseprint(f'Sleeping {sleep_time} seconds')
+ time.sleep(sleep_time)
+ update_rics()
+
+ verboseprint('Exiting main')