Skip to content
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

add links to register #2804

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions flytekit/remote/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -2399,12 +2399,15 @@ def generate_console_url(

if not isinstance(entity, (FlyteWorkflow, FlyteTask, FlyteLaunchPlan)):
raise ValueError(f"Only remote entities can be looked at in the console, got type {type(entity)}")
return self.generate_url_from_id(id=entity.id)

def generate_url_from_id(self, id: Identifier):
rt = "workflow"
if entity.id.resource_type == ResourceType.TASK:
if id.resource_type == ResourceType.TASK:
rt = "task"
elif entity.id.resource_type == ResourceType.LAUNCH_PLAN:
elif id.resource_type == ResourceType.LAUNCH_PLAN:
rt = "launch_plan"
return f"{self.generate_console_http_domain()}/console/projects/{entity.id.project}/domains/{entity.id.domain}/{rt}/{entity.name}/version/{entity.id.version}" # noqa
return f"{self.generate_console_http_domain()}/console/projects/{id.project}/domains/{id.domain}/{rt}/{id.name}/version/{id.version}"

def launch_backfill(
self,
Expand Down
44 changes: 32 additions & 12 deletions flytekit/tools/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from flytekit.tools.serialize_helpers import get_registrable_entities, persist_registrable_entities
from flytekit.tools.translator import FlyteControlPlaneEntity, Options

REGISTRATION = "Registration"


class NoSerializableEntitiesError(Exception):
pass
Expand Down Expand Up @@ -51,6 +53,7 @@ def serialize_get_control_plane_entities(
settings: SerializationSettings,
local_source_root: typing.Optional[str] = None,
options: typing.Optional[Options] = None,
is_registration: bool = False,
) -> typing.List[FlyteControlPlaneEntity]:
"""
See :py:class:`flytekit.models.core.identifier.ResourceType` to match the trailing index in the file name with the
Expand All @@ -59,12 +62,16 @@ def serialize_get_control_plane_entities(
:param settings: SerializationSettings to be used
:param pkgs: Dot-delimited Python packages/subpackages to look into for serialization.
:param local_source_root: Where to start looking for the code.
:param is_registration: Whether this is happening for registration.
"""
settings.source_root = local_source_root
ctx_builder = FlyteContextManager.current_context().with_serialization_settings(settings)
with FlyteContextManager.with_context(ctx_builder) as ctx:
registrable_entities = get_registrable_entities(ctx, options=options)
click.secho(f"Successfully serialized {len(registrable_entities)} flyte objects", fg="green")
click.secho(
f"Successfully serialized{' and registered' if is_registration else ''} {len(registrable_entities)} flyte objects",
fg="green",
)
return registrable_entities


Expand Down Expand Up @@ -199,25 +206,36 @@ def list_packages_and_modules(
return pkgs_and_modules


def secho(i: Identifier, state: str = "success", reason: str = None, op: str = "Registration"):
def secho(i: Identifier, state: str = "success", reason: str = None, op: str = REGISTRATION, console_url: str = None):
state_ind = "[ ]"
fg = "white"
nl = False
if state == "success":
state_ind = "\r[✔]"
fg = "green"
nl = True
reason = f"successful with version {i.version}" if not reason else reason
if not reason:
url_string = click.style(console_url, fg="cyan")
reason = f": {url_string}" if console_url else f" at version: {i.version}"
elif state == "failed":
state_ind = "\r[x]"
fg = "red"
nl = True
reason = "skipped!"
click.secho(
click.style(f"{state_ind}", fg=fg) + f" {op} {i.name} type {i.resource_type_name()} {reason}",
dim=True,
nl=nl,
)
if op == REGISTRATION:
name_words = i.resource_type_name().replace("_", " ").split()
name = " ".join(word.capitalize() for word in name_words)
click.secho(
click.style(f"{state_ind}", fg=fg) + f" {name} {i.name}{reason}",
dim=True,
nl=nl,
)
else:
click.secho(
click.style(f"{state_ind}", fg=fg) + f" {op} {i.name} type {i.resource_type_name()} {reason}",
dim=True,
nl=nl,
)


def register(
Expand Down Expand Up @@ -295,7 +313,9 @@ def register(
serialization_settings.version = version
click.secho(f"Computed version is {version}", fg="yellow")

registrable_entities = serialize_get_control_plane_entities(serialization_settings, str(detected_root), options)
registrable_entities = serialize_get_control_plane_entities(
serialization_settings, str(detected_root), options, is_registration=True
)

FlyteContextManager.pop_context()
if len(registrable_entities) == 0:
Expand All @@ -315,7 +335,9 @@ def _raw_register(cp_entity: FlyteControlPlaneEntity):
i = remote.raw_register(
cp_entity, serialization_settings, version=version, create_default_launchplan=False
)
secho(i, state="success")
console_url = remote.generate_url_from_id(id=i)

secho(i, state="success", console_url=console_url)
if is_lp and activate_launchplans:
secho(og_id, "", op="Activation")
remote.activate_launchplan(i)
Expand Down Expand Up @@ -344,5 +366,3 @@ async def _register(entities: typing.List[task.TaskSpec]):
cp_other_entities = list(filter(lambda x: not isinstance(x, task.TaskSpec), registrable_entities))
for entity in cp_other_entities:
_raw_register(entity)

click.secho(f"Successfully registered {len(registrable_entities)} entities", fg="green")
Loading