This repository has been archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CORTX-31068: Refactoring needed for the Hare-ha communication module
Solution: Added new base classes for resources and events. These calsses will be used as parent classes for all the resources and events. Signed-off-by: Swapnil Gaonkar <swapnil.gaonkar@seagate.com>
- Loading branch information
1 parent
c239790
commit 929122f
Showing
10 changed files
with
308 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (c) 2022 Seagate Technology LLC and/or its Affiliates | ||
# | ||
# 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. | ||
# | ||
# For any questions about this software or licensing, | ||
# please email opensource@seagate.com or cortx-questions@seagate.com. | ||
# | ||
|
||
# empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (c) 2022 Seagate Technology LLC and/or its Affiliates | ||
# | ||
# This program is free software: you can redistribute it and/or modify it | ||
# under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, | ||
# or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License | ||
# for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
# For any questions about this software or licensing, please email | ||
# opensource@seagate.com or cortx-questions@seagate.com. | ||
|
||
import logging | ||
from hax.ha.const import HEALTH_EVENT_SOURCES, NOT_DEFINED | ||
from hax.ha.event.event import HaEvent | ||
from hax.ha.event.node import NodeEvent | ||
from hax.ha.resource.resource import ResourceType | ||
|
||
|
||
class Node(ResourceType): | ||
def create_event(self, resource_id, | ||
resource_name, resource_status) -> HaEvent: | ||
logging.debug('Inside Node:create_event') | ||
event: NodeEvent = NodeEvent(source=HEALTH_EVENT_SOURCES.HARE.value, | ||
cluster_id=NOT_DEFINED, | ||
site_id=NOT_DEFINED, | ||
rack_id=NOT_DEFINED, | ||
storageset_id=NOT_DEFINED, | ||
node_id=resource_id, | ||
resource_type='node', | ||
resource_id=resource_id, | ||
resource_status=resource_status, | ||
specific_info={"generation_id": | ||
resource_name}) | ||
|
||
return event |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (c) 2022 Seagate Technology LLC and/or its Affiliates | ||
# | ||
# This program is free software: you can redistribute it and/or modify it | ||
# under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, | ||
# or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License | ||
# for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
# For any questions about this software or licensing, please email | ||
# opensource@seagate.com or cortx-questions@seagate.com. | ||
|
||
import logging | ||
|
||
|
||
class ResourceType(): | ||
def __init__(self): | ||
logging.debug('Inside ResourceType') | ||
|
||
def create_event(self, resource_id, resource_name, resource_status): | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) 2022 Seagate Technology LLC and/or its Affiliates | ||
# | ||
# 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. | ||
# | ||
# For any questions about this software or licensing, | ||
# please email opensource@seagate.com or cortx-questions@seagate.com. | ||
# | ||
|
||
from hax.ha.message_type.message_type import HealthMessage | ||
|
||
InterfaceMapping = { | ||
'health_message': HealthMessage | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Copyright (c) 2022 Seagate Technology LLC and/or its Affiliates | ||
# | ||
# This program is free software: you can redistribute it and/or modify it | ||
# under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, | ||
# or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License | ||
# for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
# For any questions about this software or licensing, please email | ||
# opensource@seagate.com or cortx-questions@seagate.com. | ||
|
||
import json | ||
from typing import Dict, List, Optional | ||
from hax.util import ConsulUtil | ||
|
||
cached_subscriber_list: List = [] | ||
is_subscriber_list_cached: bool = False | ||
|
||
|
||
class HaUtils: | ||
resource_types = ['node'] | ||
interface_types = ['health_message'] | ||
|
||
def __init__(self, consul_util: ConsulUtil): | ||
self.util = consul_util | ||
self.get_subscribers(self.util, None) | ||
|
||
# If resourse_type is None then all resource_types will be fetched | ||
def get_subscribers(self, consul_util: ConsulUtil, | ||
resourse_type: Optional[str]): | ||
global cached_subscriber_list, is_subscriber_list_cached | ||
subscriber_list: List = [] | ||
if is_subscriber_list_cached: | ||
return cached_subscriber_list | ||
|
||
if resourse_type: | ||
subscribers = consul_util.kv.kv_get( | ||
f'events/subscription/{resourse_type}', | ||
allow_null=True) | ||
subscriber_list = json.loads(subscribers['Value']) | ||
else: | ||
for resourse_type in self.resource_types: | ||
subscribers = consul_util.kv.kv_get( | ||
f'events/subscription/{resourse_type}', | ||
allow_null=True) | ||
if subscribers: | ||
subscriber_list.append(json.loads(subscribers['Value'])) | ||
cached_subscriber_list = subscriber_list | ||
is_subscriber_list_cached = True | ||
return subscriber_list | ||
|
||
def event_subscribe(self, data: Dict[str, str]): | ||
global cached_subscriber_list | ||
for item in data.keys(): | ||
if item not in self.resource_types: | ||
raise Exception(f'Invalid resource type({item})') | ||
if data[item] not in self.interface_types: | ||
raise Exception(f'Invalid interface type({data[item]})') | ||
|
||
subscriber = self.util.kv.kv_get(f'events/subscription/{item}', | ||
allow_null=True) | ||
subscriber_list = [] | ||
if subscriber: | ||
subscriber_list = json.loads(subscriber['Value']) | ||
if data[item] not in subscriber_list: | ||
subscriber_list.append(data[item]) | ||
self.util.kv.kv_put(f'events/subscription/{item}', | ||
json.dumps(subscriber_list)) | ||
cached_subscriber_list = subscriber_list | ||
|
||
def event_unsubscribe(self, data: Dict[str, str]): | ||
global cached_subscriber_list | ||
for item in data.keys(): | ||
if item not in self.resource_types: | ||
raise Exception(f'Invalid reource type({item})') | ||
if data[item] not in self.interface_types: | ||
raise Exception(f'Invalid interface type({data[item]})') | ||
|
||
subscriber = self.util.kv.kv_get(f'events/subscription/{item}', | ||
allow_null=True) | ||
subscriber_list = [] | ||
if subscriber: | ||
subscriber_list = json.loads(subscriber['Value']) | ||
if data[item] in subscriber_list: | ||
subscriber_list.remove(data[item]) | ||
self.util.kv.kv_put(f'events/subscription/{item}', | ||
json.dumps(subscriber_list)) | ||
cached_subscriber_list = subscriber_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.