-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
distributed performance metric collection framework
- Loading branch information
Amit Roushan
committed
Jun 17, 2021
1 parent
1c0a644
commit a1ea770
Showing
19 changed files
with
575 additions
and
104 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
Empty file.
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,50 @@ | ||
# Copyright 2021 The SODA Authors. | ||
# Copyright 2010 United States Government as represented by the | ||
# Administrator of the National Aeronautics and Space Administration. | ||
# Copyright 2011 Justin Santa Barbara | ||
# 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. | ||
|
||
from delfin.leader_election.tooz.callback import ToozLeaderElectionCallback | ||
from delfin.leader_election.tooz.leader_elector import Elector | ||
from delfin.task_manager.scheduler.schedule_manager import SchedulerManager | ||
|
||
LEADER_ELECTION_KEY = "delfin-performance-metric-collection" | ||
|
||
|
||
class LeaderElectionFactory: | ||
|
||
@staticmethod | ||
def construct_elector(plugin, leader_key=None): | ||
""" | ||
Construct leader election elector based on specified plugin | ||
:param string plugin: required plugin for leader election | ||
""" | ||
# maintain a unique key for metric collection leader election | ||
leader_election_key = LEADER_ELECTION_KEY | ||
if leader_key: | ||
leader_election_key = leader_key | ||
|
||
scheduler_mgr = SchedulerManager() | ||
|
||
if plugin == "tooz": | ||
# create callback object | ||
callback = ToozLeaderElectionCallback.register( | ||
on_leading_callback=scheduler_mgr.start, | ||
on_stop_callback=scheduler_mgr.stop) | ||
|
||
return Elector(callback, leader_election_key) | ||
else: | ||
raise ValueError(plugin) |
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,72 @@ | ||
# Copyright 2021 The SODA Authors. | ||
# Copyright 2010 United States Government as represented by the | ||
# Administrator of the National Aeronautics and Space Administration. | ||
# Copyright 2011 Justin Santa Barbara | ||
# 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. | ||
|
||
"""Leader election interface defined""" | ||
|
||
import six | ||
import abc | ||
|
||
|
||
@six.add_metaclass(abc.ABCMeta) | ||
class LeaderCallback: | ||
|
||
def __init__(self): | ||
self.on_started_leading_callback = None | ||
"""on_started_leading is called when elected as leader""" | ||
|
||
self.on_stopped_leading_callback = None | ||
"""on_stopped_leading is called when Leader give up its leadership""" | ||
|
||
@abc.abstractmethod | ||
def on_started_leading(self, *args, **kwargs): | ||
pass | ||
|
||
@abc.abstractmethod | ||
def on_stopped_leading(self, *args, **kwargs): | ||
pass | ||
|
||
@classmethod | ||
def register(cls, on_leading_callback, on_stop_callback): | ||
callback = cls() | ||
callback.on_started_leading_callback = on_leading_callback | ||
callback.on_stopped_leading_callback = on_stop_callback | ||
return callback | ||
|
||
|
||
@six.add_metaclass(abc.ABCMeta) | ||
class LeaderElector: | ||
|
||
def __init__(self, callbacks, election_key): | ||
self.callbacks = callbacks | ||
self.election_key = election_key | ||
|
||
@abc.abstractmethod | ||
def run(self): | ||
"""kick start leader election. | ||
invoke callback.on_started_leading callback once elected as leader | ||
invoke callback.on_stopped_leading callback once lose leadership | ||
run returns once leader losses its leadership | ||
""" | ||
pass | ||
|
||
@abc.abstractmethod | ||
def cleanup(self): | ||
"""Cleanup leader election residue | ||
""" | ||
pass |
Empty file.
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,28 @@ | ||
# Copyright 2021 The SODA Authors. | ||
# Copyright 2010 United States Government as represented by the | ||
# Administrator of the National Aeronautics and Space Administration. | ||
# Copyright 2011 Justin Santa Barbara | ||
# 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. | ||
|
||
from delfin.leader_election.interface import LeaderCallback | ||
|
||
|
||
class ToozLeaderElectionCallback(LeaderCallback): | ||
|
||
def on_started_leading(self, *args, **kwargs): | ||
return self.on_started_leading_callback() | ||
|
||
def on_stopped_leading(self, *args, **kwargs): | ||
return self.on_stopped_leading_callback() |
Oops, something went wrong.