From d1bfb33dbbe5209d31c90a65b399214e69904143 Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Mon, 7 Aug 2023 12:17:16 -0300 Subject: [PATCH 1/7] chore: updated flow.priority index and compound index to be DESCENDING --- controllers/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/__init__.py b/controllers/__init__.py index 867f9a2..e156dd5 100644 --- a/controllers/__init__.py +++ b/controllers/__init__.py @@ -46,15 +46,15 @@ def bootstrap_indexes(self) -> None: index_tuples = [ ("flows", [("flow_id", pymongo.ASCENDING)], {"unique": True}), ("flows", [("flow.cookie", pymongo.ASCENDING)], {}), - ("flows", [("flow.priority", pymongo.ASCENDING)], {}), + ("flows", [("flow.priority", pymongo.DESCENDING)], {}), ("flows", [("state", pymongo.ASCENDING)], {}), ( "flows", [ ("switch", pymongo.ASCENDING), ("flow.cookie", pymongo.ASCENDING), - ("flow.priority", pymongo.ASCENDING), ("state", pymongo.ASCENDING), + ("flow.priority", pymongo.DESCENDING), ("inserted_at", pymongo.ASCENDING), ("updated_at", pymongo.ASCENDING), ], From 142ba43c652f91318ed7f95cf04a9898b7faf5ff Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Mon, 7 Aug 2023 12:27:59 -0300 Subject: [PATCH 2/7] chore: added scripts/drop_compound_index.py --- scripts/README.md | 21 ++++++++++++++++++ scripts/drop_compound_index.py | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 scripts/drop_compound_index.py diff --git a/scripts/README.md b/scripts/README.md index 4fbacdc..9a4edd9 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -49,3 +49,24 @@ And then, to insert (or update) the flows: ``` CMD=insert_flows python3 scripts/storehouse_to_mongo.py ``` + +### Add `owner` and `table_group` fields to `flows` collections + +### Pre-requisites +Same requisites as above + +### How to use + +Run the script to upgrade all flows from `mef_eline`, `of_lldp` and `coloring` with new fields `owner` and `table_group` + +``` +python3 pipeline_related.py +``` + +### Drop compound index + +On version `2023.1`, this `flows` compound index `switch_1_flow.cookie_1_state_1_inserted_at_1_updated_at_1` has changed. If you're upgrading to `2023.1` froma previous version, you should run the `drop_compound_index.py` script to drop it: + +``` +CMD=drop_index python3 drop_compound_index.py +``` diff --git a/scripts/drop_compound_index.py b/scripts/drop_compound_index.py new file mode 100644 index 0000000..bcfe8d8 --- /dev/null +++ b/scripts/drop_compound_index.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +import sys +import os +import pymongo + +from napps.kytos.flow_manager.controllers import FlowController + + +flow_controller = FlowController() + + +def drop_index(index_name=None, flow_controller=flow_controller) -> dict: + """drop_index.""" + index_name = index_name or os.environ.get( + "INDEX_NAME", "switch_1_flow.cookie_1_state_1_inserted_at_1_updated_at_1" + ) + return flow_controller.db.flows.drop_index(index_name) + + +if __name__ == "__main__": + cmds = { + "drop_index": drop_index, + } + try: + cmd = os.environ["CMD"] + except KeyError: + print("Please set the 'CMD' env var.") + sys.exit(1) + try: + for command in cmd.split(","): + print(cmds[command]()) + except KeyError as e: + print( + f"Unknown cmd: {str(e)}. 'CMD' env var has to be one of these {list(cmds.keys())}." + ) + sys.exit(1) + except pymongo.errors.PyMongoError as e: + print(f"pymongo error: {str(e)}") + sys.exit(1) From 96f2974c13435072a1af28b9b9eda701cd561a88 Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Mon, 7 Aug 2023 13:02:38 -0300 Subject: [PATCH 3/7] chore: fixed unit test --- tests/unit/test_flow_controller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_flow_controller.py b/tests/unit/test_flow_controller.py index 67d6bc9..d0f3f4d 100644 --- a/tests/unit/test_flow_controller.py +++ b/tests/unit/test_flow_controller.py @@ -35,15 +35,15 @@ def test_boostrap_indexes(self) -> None: expected_indexes = [ ("flows", [("flow_id", 1)]), ("flows", [("flow.cookie", 1)]), - ("flows", [("flow.priority", 1)]), + ("flows", [("flow.priority", -1)]), ("flows", [("state", 1)]), ( "flows", [ ("switch", 1), ("flow.cookie", 1), - ("flow.priority", 1), ("state", 1), + ("flow.priority", -1), ("inserted_at", 1), ("updated_at", 1), ], From 2a79c5613e3588a050b15a36183d4a23b10992e3 Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Mon, 7 Aug 2023 13:08:16 -0300 Subject: [PATCH 4/7] bump: bumped 2022.3.3 --- kytos.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kytos.json b/kytos.json index e54b7a4..6a2d927 100644 --- a/kytos.json +++ b/kytos.json @@ -3,7 +3,7 @@ "username": "kytos", "name": "flow_manager", "description": "Manage switches' flows through a REST API.", - "version": "2022.3.2", + "version": "2022.3.3", "napp_dependencies": ["kytos/of_core"], "license": "MIT", "url": "https://github.com/kytos/flow_manager.git", From 3fd26b99d5ace2fa2f2c3eb489eb324894a7d0d8 Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Mon, 7 Aug 2023 13:28:03 -0300 Subject: [PATCH 5/7] Updated CHANGELOG.rst --- CHANGELOG.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 92994bf..7d697c1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,13 @@ file. [UNRELEASED] - Under development ******************************** +[2022.3.3] - 2023-08-07 +*********************** + +General Information +=================== +- ``scripts/drop_compound_index.py`` can be used to drop a compound index that has changed. If you tried to upgrade to ``2022.3.2`` before and it ended up creating ``'flow.priority_1'`` index, then you also want to delete it by running ``CMD=drop_index INDEX_NAME=flow.priority_1 python3 drop_compound_index.py`` + [2022.3.2] - 2023-07-20 *********************** From 24cf8ad474548a13b3c7fa3370aba0b7853d5e0e Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Mon, 7 Aug 2023 13:33:23 -0300 Subject: [PATCH 6/7] chore: fix typo --- scripts/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/README.md b/scripts/README.md index 9a4edd9..e022ba5 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -65,7 +65,7 @@ python3 pipeline_related.py ### Drop compound index -On version `2023.1`, this `flows` compound index `switch_1_flow.cookie_1_state_1_inserted_at_1_updated_at_1` has changed. If you're upgrading to `2023.1` froma previous version, you should run the `drop_compound_index.py` script to drop it: +On version `2023.1`, this `flows` compound index `switch_1_flow.cookie_1_state_1_inserted_at_1_updated_at_1` has changed. If you're upgrading to `2023.1` from a previous version, you should run the `drop_compound_index.py` script to drop it: ``` CMD=drop_index python3 drop_compound_index.py From 83ae2c23bdb757bed360ddc3618e159dc0bec719 Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Mon, 7 Aug 2023 14:00:00 -0300 Subject: [PATCH 7/7] chore: updated README.md --- scripts/README.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index e022ba5..f9e2e1c 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -50,19 +50,6 @@ And then, to insert (or update) the flows: CMD=insert_flows python3 scripts/storehouse_to_mongo.py ``` -### Add `owner` and `table_group` fields to `flows` collections - -### Pre-requisites -Same requisites as above - -### How to use - -Run the script to upgrade all flows from `mef_eline`, `of_lldp` and `coloring` with new fields `owner` and `table_group` - -``` -python3 pipeline_related.py -``` - ### Drop compound index On version `2023.1`, this `flows` compound index `switch_1_flow.cookie_1_state_1_inserted_at_1_updated_at_1` has changed. If you're upgrading to `2023.1` from a previous version, you should run the `drop_compound_index.py` script to drop it: