forked from NVIDIA/NVFlare
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore non-aio GRPC and a few improvements (NVIDIA#2058)
* restore non-aio grpc driver * restore non-aio grpc driver * fix unit tests * fix drivers * fix CP HB bug; add retry for result submit * fix test cases * fix test case * address pr review * fix download_job bug in flare_api
- Loading branch information
1 parent
bc3d5bd
commit 571f17f
Showing
22 changed files
with
677 additions
and
159 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
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,52 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION. 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. | ||
|
||
import logging | ||
import queue | ||
|
||
|
||
class QueueClosed(Exception): | ||
pass | ||
|
||
|
||
class QQ: | ||
def __init__(self): | ||
self.q = queue.Queue() | ||
self.closed = False | ||
self.logger = logging.getLogger(self.__class__.__name__) | ||
|
||
def close(self): | ||
self.closed = True | ||
|
||
def append(self, i): | ||
if self.closed: | ||
raise QueueClosed("queue stopped") | ||
self.q.put_nowait(i) | ||
|
||
def __iter__(self): | ||
return self | ||
|
||
def __next__(self): | ||
if self.closed: | ||
raise StopIteration() | ||
while True: | ||
try: | ||
return self.q.get(block=True, timeout=0.1) | ||
except queue.Empty: | ||
if self.closed: | ||
self.logger.debug("Queue closed - stop iteration") | ||
raise StopIteration() | ||
except Exception as e: | ||
self.logger.error(f"queue exception {type(e)}") | ||
raise e |
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,51 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION. 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. | ||
import grpc | ||
|
||
from nvflare.fuel.f3.comm_config import CommConfigurator | ||
from nvflare.fuel.f3.drivers.driver_params import DriverParams | ||
|
||
|
||
def use_aio_grpc(): | ||
configurator = CommConfigurator() | ||
return configurator.use_aio_grpc(default=True) | ||
|
||
|
||
def get_grpc_client_credentials(params: dict): | ||
root_cert = _read_file(params.get(DriverParams.CA_CERT.value)) | ||
cert_chain = _read_file(params.get(DriverParams.CLIENT_CERT)) | ||
private_key = _read_file(params.get(DriverParams.CLIENT_KEY)) | ||
return grpc.ssl_channel_credentials( | ||
certificate_chain=cert_chain, private_key=private_key, root_certificates=root_cert | ||
) | ||
|
||
|
||
def get_grpc_server_credentials(params: dict): | ||
root_cert = _read_file(params.get(DriverParams.CA_CERT.value)) | ||
cert_chain = _read_file(params.get(DriverParams.SERVER_CERT)) | ||
private_key = _read_file(params.get(DriverParams.SERVER_KEY)) | ||
|
||
return grpc.ssl_server_credentials( | ||
[(private_key, cert_chain)], | ||
root_certificates=root_cert, | ||
require_client_auth=True, | ||
) | ||
|
||
|
||
def _read_file(file_name: str): | ||
if not file_name: | ||
return None | ||
|
||
with open(file_name, "rb") as f: | ||
return f.read() |
Oops, something went wrong.