Skip to content

Commit 0367e97

Browse files
fiedlerNr9Atharva1723
authored andcommitted
add project & domain endpoint for FlyteRemote (flyteorg#3108)
* add domain model Signed-off-by: Jan Fiedler <[email protected]> * fix docstring domain models Signed-off-by: Jan Fiedler <[email protected]> * add get domains endpoint for raw client Signed-off-by: Jan Fiedler <[email protected]> * add get domains endpoint to friendly client Signed-off-by: Jan Fiedler <[email protected]> * add list_projects_paginated & get_domains to FlyteRemote Signed-off-by: Jan Fiedler <[email protected]> * put max_iters decrement in while loop Signed-off-by: Jan Fiedler <[email protected]> * rename list_projects_paginated to list_projects & adjust logic accordingly Signed-off-by: Jan Fiedler <[email protected]> --------- Signed-off-by: Jan Fiedler <[email protected]> Signed-off-by: Atharva <[email protected]>
1 parent 23b9dee commit 0367e97

File tree

4 files changed

+112
-1
lines changed

4 files changed

+112
-1
lines changed

flytekit/clients/friendly.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from flytekit.clients.raw import RawSynchronousFlyteClient as _RawSynchronousFlyteClient
2323
from flytekit.models import common as _common
24+
from flytekit.models import domain as _domain
2425
from flytekit.models import execution as _execution
2526
from flytekit.models import filters as _filters
2627
from flytekit.models import launch_plan as _launch_plan
@@ -896,6 +897,21 @@ def list_projects_paginated(self, limit=100, token=None, filters=None, sort_by=N
896897
str(projects.token),
897898
)
898899

900+
####################################################################################################################
901+
#
902+
# Domain Endpoints
903+
#
904+
####################################################################################################################
905+
906+
def get_domains(self):
907+
"""
908+
This returns a list of domains.
909+
910+
:rtype: list[flytekit.models.Domain]
911+
"""
912+
domains = super(SynchronousFlyteClient, self).get_domains()
913+
return [_domain.Domain.from_flyte_idl(domain) for domain in domains.domains]
914+
899915
####################################################################################################################
900916
#
901917
# Matching Attributes Endpoints

flytekit/clients/raw.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import typing
44

55
import grpc
6-
from flyteidl.admin.project_pb2 import ProjectListRequest
6+
from flyteidl.admin.project_pb2 import GetDomainRequest, ProjectListRequest
77
from flyteidl.admin.signal_pb2 import SignalList, SignalListRequest, SignalSetRequest, SignalSetResponse
88
from flyteidl.service import admin_pb2_grpc as _admin_service
99
from flyteidl.service import dataproxy_pb2 as _dataproxy_pb2
@@ -520,6 +520,21 @@ def update_project(self, project):
520520
"""
521521
return self._stub.UpdateProject(project, metadata=self._metadata)
522522

523+
####################################################################################################################
524+
#
525+
# Domain Endpoints
526+
#
527+
####################################################################################################################
528+
529+
def get_domains(self):
530+
"""
531+
This will return a list of domains registered with the Flyte Admin Service
532+
:param flyteidl.admin.project_pb2.GetDomainRequest get_domain_request:
533+
:rtype: flyteidl.admin.project_pb2.GetDomainsResponse
534+
"""
535+
get_domain_request = GetDomainRequest()
536+
return self._stub.GetDomains(get_domain_request, metadata=self._metadata)
537+
523538
####################################################################################################################
524539
#
525540
# Matching Attributes Endpoints

flytekit/models/domain.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from flyteidl.admin import project_pb2 as _project_pb2
2+
3+
from flytekit.models import common as _common
4+
5+
6+
class Domain(_common.FlyteIdlEntity):
7+
"""
8+
Domains are fixed and unique at the global level, and provide an abstraction to isolate resources and feature configuration for different deployment environments.
9+
10+
:param Text id: A globally unique identifier associated with this domain.
11+
:param Text name: A human-readable name for this domain.
12+
"""
13+
14+
def __init__(self, id, name):
15+
self._id = id
16+
self._name = name
17+
18+
@property
19+
def id(self):
20+
"""
21+
A globally unique identifier associated with this domain.
22+
:rtype: Text
23+
"""
24+
return self._id
25+
26+
@property
27+
def name(self):
28+
"""
29+
A human-readable name for this domain.
30+
:rtype: Text
31+
"""
32+
return self._name
33+
34+
def to_flyte_idl(self):
35+
"""
36+
:rtype: flyteidl.admin.project_pb2.Domain
37+
"""
38+
return _project_pb2.Domain(id=self.id, name=self.name)
39+
40+
@classmethod
41+
def from_flyte_idl(cls, pb2_object):
42+
"""
43+
:param flyteidl.admin.project_pb2.Domain pb2_object:
44+
:rtype: Domain
45+
"""
46+
return cls(id=pb2_object.id, name=pb2_object.name)

flytekit/remote/remote.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
from flytekit.models.core import workflow as workflow_model
8383
from flytekit.models.core.identifier import Identifier, ResourceType, SignalIdentifier, WorkflowExecutionIdentifier
8484
from flytekit.models.core.workflow import BranchNode, Node, NodeMetadata
85+
from flytekit.models.domain import Domain
8586
from flytekit.models.execution import (
8687
ClusterAssignment,
8788
ExecutionMetadata,
@@ -93,6 +94,7 @@
9394
from flytekit.models.launch_plan import LaunchPlanState
9495
from flytekit.models.literals import Literal, LiteralMap
9596
from flytekit.models.matchable_resource import ExecutionClusterLabel
97+
from flytekit.models.project import Project
9698
from flytekit.remote.backfill import create_backfill_workflow
9799
from flytekit.remote.data import download_literal
98100
from flytekit.remote.entities import FlyteLaunchPlan, FlyteNode, FlyteTask, FlyteTaskNode, FlyteWorkflow
@@ -2613,6 +2615,38 @@ def terminate(self, execution: FlyteWorkflowExecution, cause: str):
26132615
"""
26142616
self.client.terminate_execution(execution.id, cause)
26152617

2618+
############
2619+
# Projects #
2620+
############
2621+
2622+
def list_projects(
2623+
self,
2624+
limit: typing.Optional[int] = 100,
2625+
filters: typing.Optional[typing.List[filter_models.Filter]] = None,
2626+
sort_by: typing.Optional[admin_common_models.Sort] = None,
2627+
) -> typing.List[Project]:
2628+
"""Lists registered projects from flyte admin.
2629+
2630+
:param limit: [Optional[int]] The maximum number of entries to return.
2631+
:param filters Optional[typing.List[filter_models.Filter]]: If specified, the filters will be applied to
2632+
the query. If the filter is not supported, an exception will be raised.
2633+
:param sort_by Optional[admin_common_models.Sort]: If provided, the results will be sorted.
2634+
:raises grpc.RpcError:
2635+
:returns: typing.List[flytekit.models.project.Project]
2636+
"""
2637+
return self.client.list_projects_paginated(limit=limit, filters=filters, sort_by=sort_by)[0]
2638+
2639+
############
2640+
# Domains #
2641+
############
2642+
2643+
def get_domains(self) -> typing.List[Domain]:
2644+
"""Lists registered domains from flyte admin.
2645+
2646+
:returns: typing.List[flytekit.models.domain.Domain]
2647+
"""
2648+
return self.client.get_domains()
2649+
26162650
##################
26172651
# Helper Methods #
26182652
##################

0 commit comments

Comments
 (0)