def run(client: ModelPackagingClient, pack_id: str, manifest_file: List[str], manifest_dir: List[str], artifact_path: str, artifact_name: str, is_target_disabled: bool): """ \b Start a packaging process locally. \b Usage example: * odahuflowctl local pack run --id wine \f """ entities: List[OdahuflowCloudResourceUpdatePair] = [] for file_path in manifest_file: entities.extend(parse_resources_file(file_path).changes) for dir_path in manifest_dir: entities.extend(parse_resources_dir(dir_path)) mp: Optional[ModelPackaging] = None packagers: Dict[str, PackagingIntegration] = {} for entity in map(lambda x: x.resource, entities): if isinstance(entity, PackagingIntegration): packagers[entity.id] = entity elif isinstance(entity, ModelPackaging) and entity.id == pack_id: mp = entity if not mp: click.echo( f'The {pack_id} packaging not found in the manifest files.' f' Trying to retrieve it from API server' ) mp = client.get(pack_id) integration_name = mp.spec.integration_name packager = packagers.get(integration_name) if not packager: click.echo( f'The {integration_name} packager not found in the manifest files.' f' Trying to retrieve it from API server' ) packager = PackagingIntegrationClient.construct_from_other(client).get(integration_name) if artifact_name: mp.spec.artifact_name = artifact_name LOGGER.debug('Override the artifact name') if is_target_disabled: mp.spec.targets = [] k8s_packager = K8sPackager( model_packaging=mp, packaging_integration=packager, targets=[], ) result = start_package(k8s_packager, artifact_path) click.echo('Packager results:') for key, value in result.items(): click.echo(f'* {key} - {value}')
def wait_packaging_finish(timeout: int, wait: bool, mp_id: str, mp_client: ModelPackagingClient): """ Wait for packaging to finish according to command line arguments :param wait: :param timeout: :param mp_id: Model Packaging name :param mp_client: Model Packaging Client """ if not wait: return start = time.time() if timeout <= 0: raise Exception( 'Invalid --timeout argument: should be positive integer') # We create a separate client for logs because it has the different timeout settings log_mp_client = ModelPackagingClient.construct_from_other(mp_client) log_mp_client.timeout = mp_client.timeout, LOG_READ_TIMEOUT_SECONDS click.echo("Logs streaming...") while True: elapsed = time.time() - start if elapsed > timeout: raise Exception(TIMEOUT_ERROR_MESSAGE) try: mp = mp_client.get(mp_id) if mp.status.state == SUCCEEDED_STATE: click.echo( f'Model {mp_id} was packed. Packaging took {round(time.time() - start)} seconds' ) return elif mp.status.state == FAILED_STATE: raise Exception(f'Model packaging {mp_id} was failed.') elif mp.status.state == "": click.echo( f"Can't determine the state of {mp.id}. Sleeping...") else: for msg in log_mp_client.log(mp.id, follow=True): print_logs(msg) except (WrongHttpStatusCode, HTTPException, RequestException, APIConnectionException) as e: LOGGER.info( 'Callback have not confirmed completion of the operation. Exception: %s', str(e)) LOGGER.debug('Sleep before next request') time.sleep(DEFAULT_WAIT_TIMEOUT)
def get(client: ModelPackagingClient, pack_id: str, output_format: str): """ \b Get packagings. The command without id argument retrieve all packagings. \b Get all packagings in json format: odahuflowctl pack get --output-format json \b Get packaging with "git-repo" id: odahuflowctl pack get --id git-repo \b Using jsonpath: odahuflowctl pack get -o 'jsonpath=[*].spec.reference' \f :param client: Model packaging HTTP client :param pack_id: Model packaging ID :param output_format: Output format :return: """ packs = [client.get(pack_id)] if pack_id else client.get_all() format_output(packs, output_format)