From eea99bd4771275fe0877f04be02722388db0af54 Mon Sep 17 00:00:00 2001 From: ArqamFarooqui110719 Date: Mon, 12 Feb 2024 13:13:50 +0530 Subject: [PATCH 1/2] updated attribute deleting script with python3 --- CHANGES_NEXT_RELEASE | 1 + scripts/utils/delete_attribute_by_query.py | 37 +++++++++++----------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index fdb575ad63..0fee87c741 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,3 +1,4 @@ - Fix: changed the default value of `-dbTimeout` to 0 to resolve conflict with `-dbURI` (#4496) - Fix: wrong INFO startup log showing ORION_MONGO_TIMEOUT, ORION_IN_REQ_PAYLOAD_MAX_SIZE and ORION_OUT_REQ_MSG_MAX_SIZE env var values (#4496) - Fix: return 400 Bad Request when subject.entities exists but it is an empty array (#4499) +- Fix: Attribute deleting script is not working (#4508) diff --git a/scripts/utils/delete_attribute_by_query.py b/scripts/utils/delete_attribute_by_query.py index 9351606563..8c6054bc07 100755 --- a/scripts/utils/delete_attribute_by_query.py +++ b/scripts/utils/delete_attribute_by_query.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright 2019 Telefonica Investigacion y Desarrollo, S.A.U # # This file is part of Orion Context Broker. @@ -53,7 +53,7 @@ def testing_populate(n, entity_type): :param n: number of entities to populate (with ids from e1 to e) :param entity_type: entity type used for the populated entities (all with the same type) """ - print 'Populating %d entities of type %s' % (n, entity_type) + print('Populating %d entities of type %s' % (n, entity_type)) entities = [] for i in range(0, n): @@ -78,7 +78,7 @@ def testing_populate(n, entity_type): res = requests.post(cb_endpoint + '/v2/op/update', json=body, headers=headers, verify=False) if res.status_code != 204: - print 'Error populating entities (%d): %s' % (res.status_code, res.json()) + print('Error populating entities (%d): %s' % (res.status_code, res.json())) def get_entities_count(): @@ -92,7 +92,7 @@ def get_entities_count(): res = requests.get(cb_endpoint + '/v2/entities?limit=1&options=count&attrs=noexist' + filter, headers=headers, verify=False) if res.status_code != 200: - print 'Error getting entities count (%d): %s' % (res.status_code, res.json()) + print('Error getting entities count (%d): %s' % (res.status_code, res.json())) return -1 else: return int(res.headers['fiware-total-count']) @@ -105,10 +105,10 @@ def initial_statistics(): :return: the total number of entities """ total = get_entities_count() - print 'There are %d entities' % total - pages = total / page_size + print('There are %d entities' % total) + pages = total // page_size rest = total - (pages * page_size) - print 'There are %d pages of %d entities (and a final page of %d entities)' % (pages, page_size, rest) + print('There are %d pages of %d entities (and a final page of %d entities)' % (pages, page_size, rest)) return total @@ -128,7 +128,7 @@ def send_batch(entities): res = requests.post(cb_endpoint + '/v2/op/update?options=keyValues', json=body, headers=headers, verify=False) if res.status_code != 204: - print 'Error in batch operation (%d): %s' % (res.status_code, res.json()) + print('Error in batch operation (%d): %s' % (res.status_code, res.json())) return False return True @@ -137,10 +137,10 @@ def send_batch(entities): ### Main program starts here ### # Warn user -print "WARNING!!!! This script will delete the atrribute '%s' in all the entities matching the filter '%s'" % (attr_to_delete, filter) -print "This action cannot be undone. If you are sure you want to continue type 'yes' and press Enter" +print("WARNING!!!! This script will delete the atrribute '%s' in all the entities matching the filter '%s'" % (attr_to_delete, filter)) +print("This action cannot be undone. If you are sure you want to continue type 'yes' and press Enter") -confirm = raw_input() +confirm = input() if (confirm != 'yes'): sys.exit() @@ -150,21 +150,21 @@ def send_batch(entities): count = initial_statistics() if count == 0: - print 'Nothing to do' + print('Nothing to do') sys.exit(0) entities = [] # Number of batches -pages = count / page_size +pages = count // page_size for i in range(0, pages + 1): - print '- Getting entities page %d' % (i + 1) + print('- Getting entities page %d' % (i + 1)) offset = i * page_size res = requests.get('%s/v2/entities?offset=%s&limit=%s%s' % (cb_endpoint, str(offset), str(page_size), filter), headers=headers, verify=False) if res.status_code != 200: - print 'Error getting entities (%d): %s' % (res.status_code, res.json()) + print('Error getting entities (%d): %s' % (res.status_code, res.json())) sys.exit(1) for entity in res.json(): @@ -178,14 +178,15 @@ def send_batch(entities): accum += 1 if (accum == page_size): - print '- Update batch of %d entities' % len(batch) + print('- Update batch of %d entities' % len(batch)) send_batch(batch) accum = 0 batch = [] # Last batch if len(batch) > 0: - print '- Update batch of %d entities' % len(batch) + print('- Update batch of %d entities' % len(batch)) send_batch(batch) -print 'We are done!' +print('We are done!') + From 498d13368d615f8ba1a471feb4d981fa0c1ffd0c Mon Sep 17 00:00:00 2001 From: ArqamFarooqui110719 Date: Mon, 12 Feb 2024 17:05:44 +0530 Subject: [PATCH 2/2] updated CNR --- CHANGES_NEXT_RELEASE | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 0fee87c741..fdb575ad63 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,4 +1,3 @@ - Fix: changed the default value of `-dbTimeout` to 0 to resolve conflict with `-dbURI` (#4496) - Fix: wrong INFO startup log showing ORION_MONGO_TIMEOUT, ORION_IN_REQ_PAYLOAD_MAX_SIZE and ORION_OUT_REQ_MSG_MAX_SIZE env var values (#4496) - Fix: return 400 Bad Request when subject.entities exists but it is an empty array (#4499) -- Fix: Attribute deleting script is not working (#4508)