-
Notifications
You must be signed in to change notification settings - Fork 25
CSI-5277/ separate addon code from controller server #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
matancarmeli7
wants to merge
6
commits into
develop
Choose a base branch
from
task/CSI-5277_separate_addons_code_from_controller_server
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e44ba73
separate addon code from controller server
matancarmeli7 583fc2d
fix unit tests
matancarmeli7 651d221
unify server_manager
matancarmeli7 f7bb94b
Merge branch 'develop' into task/CSI-5277_separate_addons_code_from_c…
matancarmeli7 6287eee
remove identity_controller_servicer.py
matancarmeli7 5e0fef2
Merge branch 'develop' into task/CSI-5277_separate_addons_code_from_c…
matancarmeli7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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.
50 changes: 50 additions & 0 deletions
50
controllers/servers/csi/csi_addons_server/csi_addons_server_manager.py
This file contains hidden or 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 @@ | ||
import os | ||
import time | ||
from concurrent import futures | ||
|
||
import grpc | ||
from csi_general import identity_pb2_grpc, replication_pb2_grpc | ||
|
||
from controllers.common.csi_logger import get_stdout_logger | ||
from controllers.common.settings import CSI_CONTROLLER_SERVER_WORKERS | ||
from controllers.servers.csi.csi_addons_server.replication_controller_servicer import ReplicationControllerServicer | ||
from controllers.servers.csi.csi_addons_server.identity_controller_servicer import IdentityControllerServicer | ||
|
||
logger = get_stdout_logger() | ||
|
||
|
||
def get_max_workers_count(): | ||
cpu_count = (os.cpu_count() or 1) + 4 | ||
return CSI_CONTROLLER_SERVER_WORKERS if cpu_count < CSI_CONTROLLER_SERVER_WORKERS else None | ||
|
||
|
||
class CSIAddonsServerManager: | ||
def __init__(self, csi_addons_endpoint): | ||
self.endpoint = csi_addons_endpoint | ||
self.replication_servicer = ReplicationControllerServicer() | ||
self.identity_servicer = IdentityControllerServicer() | ||
|
||
def start_server(self): | ||
max_workers = get_max_workers_count() | ||
csi_addons_server = grpc.server(futures.ThreadPoolExecutor(max_workers=max_workers)) | ||
|
||
replication_pb2_grpc.add_ControllerServicer_to_server(self.replication_servicer, csi_addons_server) | ||
identity_pb2_grpc.add_IdentityServicer_to_server(self.identity_servicer, csi_addons_server) | ||
|
||
# bind the server to the port defined above | ||
# controller_server.add_insecure_port('[::]:{}'.format(self.server_port)) | ||
# controller_server.add_insecure_port('unix://{}'.format(self.server_port)) | ||
csi_addons_server.add_insecure_port(self.endpoint) | ||
|
||
# start the server | ||
logger.debug("Listening for connections on endpoint address: {}".format(self.endpoint)) | ||
|
||
csi_addons_server.start() | ||
logger.debug('CSI Addons Server running ...') | ||
|
||
try: | ||
while True: | ||
time.sleep(60 * 60 * 60) | ||
except KeyboardInterrupt: | ||
csi_addons_server.stop(0) | ||
logger.debug('CSI Addons Server Stopped ...') |
50 changes: 50 additions & 0 deletions
50
controllers/servers/csi/csi_addons_server/identity_controller_servicer.py
This file contains hidden or 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 @@ | ||
import grpc | ||
|
||
from csi_general import identity_pb2 as pb2 | ||
from csi_general import identity_pb2_grpc as pb2_grpc | ||
|
||
from controllers.common.config import config as common_config | ||
from controllers.servers.csi.decorators import csi_method | ||
from controllers.servers.csi.exception_handler import build_error_response | ||
from controllers.common.csi_logger import get_stdout_logger | ||
|
||
logger = get_stdout_logger() | ||
|
||
|
||
class IdentityControllerServicer(pb2_grpc.IdentityServicer): | ||
|
||
@csi_method(error_response_type=pb2.GetIdentityResponse) | ||
def GetIdentity(self, request, context): | ||
name = common_config.identity.name | ||
version = common_config.identity.version | ||
|
||
if not name or not version: | ||
message = "plugin name or version cannot be empty" | ||
return build_error_response(message, context, grpc.StatusCode.INTERNAL, pb2.GetIdentityResponse) | ||
|
||
return pb2.GetIdentityResponse(name=name, vendor_version=version) | ||
|
||
def GetCapabilities(self, request, context): | ||
logger.info("GetCapabilities") | ||
response = pb2.GetCapabilitiesResponse( | ||
capabilities=[self._get_replication_capability(), | ||
self._get_controller_capability()]) | ||
|
||
logger.info("finished GetCapabilities") | ||
return response | ||
|
||
def _get_replication_capability(self): | ||
types = pb2.Capability.VolumeReplication.Type | ||
capability_enum_value = types.Value("VOLUME_REPLICATION") | ||
return pb2.Capability( | ||
volume_replication=pb2.Capability.VolumeReplication(type=capability_enum_value)) | ||
|
||
def _get_controller_capability(self): | ||
types = pb2.Capability.Service.Type | ||
capability_enum_value = types.Value("CONTROLLER_SERVICE") | ||
return pb2.Capability( | ||
service=pb2.Capability.Service(type=capability_enum_value)) | ||
|
||
def Probe(self, request, context): | ||
context.set_code(grpc.StatusCode.OK) | ||
return pb2.ProbeResponse() |
File renamed without changes.
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.