def resolve(run: BaseRun, compiled_at: datetime = None, resolver_cls=None): resolver_cls = resolver_cls or CorePlatformResolver try: project = run.project return resolver.resolve( run=run, compiled_operation=V1CompiledOperation.read(run.content), owner_name=project.owner.name, project_name=project.name, project_uuid=project.uuid.hex, run_uuid=run.uuid.hex, run_name=run.name, run_path=run.subpath, resolver_cls=resolver_cls, params=None, compiled_at=compiled_at, created_at=run.created_at, cloning_kind=run.cloning_kind, original_uuid=run.original.uuid.hex if run.original_id else None, ) except ( AccessNotAuthorized, AccessNotFound, ) as e: raise PolyaxonCompilerError("Access Error: %s" % e) from e except ( AccessNotAuthorized, AccessNotFound, MarshmallowValidationError, PolyaxonSchemaError, ValidationError, ) as e: raise PolyaxonCompilerError("Compilation Error: %s" % e) from e
def convert( namespace: str, owner_name: str, project_name: str, run_name: str, run_uuid: str, run_path: str, compiled_operation: V1CompiledOperation, artifacts_store: Optional[V1ConnectionType], connection_by_names: Optional[Dict[str, V1ConnectionType]], secrets: Optional[Iterable[V1K8sResourceType]], config_maps: Optional[Iterable[V1K8sResourceType]], polyaxon_sidecar: V1PolyaxonSidecarContainer = None, polyaxon_init: V1PolyaxonInitContainer = None, default_sa: str = None, converters: Dict[str, Any] = CORE_CONVERTERS, internal_auth: bool = False, default_auth: bool = False, ) -> Dict: if compiled_operation.has_pipeline: raise PolyaxonCompilerError( "Converter Error. " "Specification with matrix/dag/schedule section is not supported in this function." ) run_kind = compiled_operation.get_run_kind() if run_kind not in converters: raise PolyaxonCompilerError( "Converter Error. " "Specification with run kind: {} is not supported in this deployment version.".format( run_kind ) ) converter = converters[run_kind]( owner_name=owner_name, project_name=project_name, run_name=run_name, run_uuid=run_uuid, namespace=namespace, polyaxon_init=polyaxon_init, polyaxon_sidecar=polyaxon_sidecar, internal_auth=internal_auth, run_path=run_path, ) if converter: resource = converter.get_resource( compiled_operation=compiled_operation, artifacts_store=artifacts_store, connection_by_names=connection_by_names, secrets=secrets, config_maps=config_maps, default_sa=default_sa, default_auth=default_auth, ) api = k8s_client.ApiClient() return api.sanitize_for_serialization(resource)
def resolve( owner_name: str, project_name: str, project_uuid: str, run_name: str, run_uuid: str, run_path: str, compiled_operation: V1CompiledOperation, params: Optional[Dict[str, Dict]], run=None, resolver_cls=None, ): resolver_cls = resolver_cls or CoreResolver run_kind = compiled_operation.get_run_kind() if run_kind not in resolver_cls.KINDS: raise PolyaxonCompilerError( "Specification with run kind: {} is not supported in this deployment version." .format(run_kind)) resolver = resolver_cls( run=run, compiled_operation=compiled_operation, owner_name=owner_name, project_name=project_name, project_uuid=project_uuid, run_name=run_name, run_path=run_path, run_uuid=run_uuid, params=params, ) if resolver: return resolver, resolver.resolve()
def apply_content(self): try: self.compiled_operation = CompiledOperationSpecification.apply_context( self.compiled_operation) except Exception as e: raise PolyaxonCompilerError( "Could not apply run context, error: {}".format(repr(e)))
def __init__( self, run, compiled_operation: V1CompiledOperation, owner_name: str, project_name: str, project_uuid: str, run_name: str, run_uuid: str, run_path: str, params: Optional[Dict], ): if not compiled_operation: raise PolyaxonCompilerError( "A run spec is required for resolution.") self.run = run self.compiled_operation = compiled_operation self.owner_name = owner_name self.project_name = project_name self.project_uuid = project_uuid self.run_name = run_name self.run_uuid = run_uuid self.run_path = run_path self.params = params or {} self.connection_by_names = {} self.namespace = None self.artifacts_store = None self.secrets = None self.config_maps = None self.polyaxon_sidecar = None self.polyaxon_init = None self.iteration = None self.agent_config = None self.contexts = {} self.globals = {}
def resolve_contexts( namespace: str, owner_name: str, project_name: str, project_uuid: str, run_uuid: str, run_name: str, run_path: str, compiled_operation: V1CompiledOperation, artifacts_store: V1ConnectionType, connection_by_names: Dict[str, V1ConnectionType], iteration: int, created_at: datetime, compiled_at: datetime, schedule_at: datetime = None, started_at: datetime = None, finished_at: datetime = None, duration: int = None, cloning_kind: V1CloningKind = None, original_uuid: str = None, ) -> Dict: run_kind = compiled_operation.get_run_kind() if run_kind not in CONTEXTS_MANAGERS: raise PolyaxonCompilerError( "Contexts manager Error. " "Specification with run kind: {} is not supported in this deployment version".format( run_kind ) ) resolved_contexts = resolve_globals_contexts( namespace=namespace, owner_name=owner_name, project_name=project_name, project_uuid=project_uuid, run_uuid=run_uuid, run_name=run_name, run_path=run_path, iteration=iteration, created_at=created_at, compiled_at=compiled_at, schedule_at=schedule_at, started_at=started_at, finished_at=finished_at, duration=duration, plugins=compiled_operation.plugins, artifacts_store=artifacts_store, cloning_kind=cloning_kind, original_uuid=original_uuid, ) return CONTEXTS_MANAGERS[run_kind].resolve( namespace=namespace, owner_name=owner_name, project_name=project_name, run_uuid=run_uuid, contexts=resolved_contexts, compiled_operation=compiled_operation, connection_by_names=connection_by_names, )
def is_kind_supported(cls, compiled_operation: V1CompiledOperation): run_kind = compiled_operation.get_run_kind() if run_kind not in cls.KINDS: raise PolyaxonCompilerError( "Resolver Error. " "Specification with run kind: {} " "is not supported in this deployment version.".format(run_kind) )
def apply_operation_contexts(self): try: self.compiled_operation = CompiledOperationSpecification.apply_operation_contexts( self.compiled_operation, param_spec=self._param_spec, contexts=self.globals, ) except Exception as e: raise PolyaxonCompilerError( "Could not apply run context, error: {}".format(repr(e)))
def __init__( self, run, compiled_operation: V1CompiledOperation, owner_name: str, project_name: str, project_uuid: str, run_name: str, run_uuid: str, run_path: str, params: Optional[Dict], created_at: datetime = None, compiled_at: datetime = None, cloning_kind: V1CloningKind = None, original_uuid: str = None, eager: bool = False, ): if not compiled_operation: raise PolyaxonCompilerError("A run spec is required for resolution.") self.run = run self.compiled_operation = compiled_operation self.owner_name = owner_name self.project_name = project_name self.project_uuid = project_uuid self.project_uuid = project_uuid or project_name self.run_name = run_name self.run_uuid = run_uuid or run_name self.run_path = run_path self.params = params or {} self.connection_by_names = {} self.namespace = None self.artifacts_store = None self.secrets = None self.config_maps = None self.polyaxon_sidecar = None self.polyaxon_init = None self.iteration = None self.agent_config = None self.globals = {} self.artifacts = [] self.created_at = created_at self.compiled_at = compiled_at self.schedule_at = None self.started_at = None self.finished_at = None self.duration = None self.eager = eager self.cloning_kind = cloning_kind self.original_uuid = original_uuid self._param_spec = {}
def _resolve_connections(self, connections: List[str], agent_config: AgentConfig): if connections: connection_by_names = {} missing_connections = set() for c in connections: if c not in agent_config.connections_by_names: missing_connections.add(c) else: connection_by_names[c] = agent_config.connections_by_names[c] if missing_connections: raise PolyaxonCompilerError( "Some Connection refs were provided " "but were not found in the " "agent.connections catalog: `{}`".format(missing_connections) ) self.connection_by_names.update(connection_by_names)
def resolve(self, compiled_operation: V1CompiledOperation, agent_config: AgentConfig = None): agent_config = agent_config or settings.AGENT_CONFIG if not agent_config: raise PolyaxonCompilerError("Polypod is not configured.") self._resolve_run_connections(compiled_operation=compiled_operation, agent_config=agent_config) self.artifacts_store = agent_config.artifacts_store self.secrets = agent_config.secrets self.config_maps = agent_config.config_maps self.polyaxon_sidecar = agent_config.sidecar or get_default_sidecar_container( ) self.polyaxon_init = agent_config.init or get_default_init_container() self.namespace = agent_config.namespace
def resolve(self, compiled_operation: V1CompiledOperation, agent_config: AgentConfig = None): if not agent_config and settings.AGENT_CONFIG: agent_config = settings.AGENT_CONFIG.clone() if not agent_config: raise PolyaxonCompilerError( "Polypod configuration not found or agent not configured.") self.default_sa = agent_config.runs_sa self._resolve_run_connections(compiled_operation=compiled_operation, agent_config=agent_config) self.artifacts_store = agent_config.artifacts_store self.secrets = agent_config.secrets self.config_maps = agent_config.config_maps self.polyaxon_sidecar = agent_config.sidecar or get_default_sidecar_container( ) self.polyaxon_init = agent_config.init or get_default_init_container() self.namespace = agent_config.namespace self.polyaxon_sidecar.monitor_logs = agent_config.is_replica
def resolve(run: BaseRun, resolver_cls=None): resolver_cls = resolver_cls or CorePlatformResolver try: project = run.project return resolver.resolve( run=run, compiled_operation=V1CompiledOperation.read(run.content), owner_name=project.owner.name, project_name=project.name, project_uuid=project.uuid.hex, run_uuid=run.uuid.hex, run_name=run.name, run_path=run.subpath, resolver_cls=resolver_cls, params=None, ) except ( AccessNotAuthorized, AccessNotFound, ValidationError, PolyaxonSchemaError, ) as e: raise PolyaxonCompilerError("Compilation Error: %s" % e) from e