def process_tenant_instances()

in docker/executor.py [0:0]


def process_tenant_instances(metrics_dir, reports_dir,
                             input_storage, output_storage,
                             parent_meta: ParentMeta,
                             licensed_parent: Parent,
                             algorithm: Algorithm,
                             license_: License,
                             customer: str,
                             tenant: str,
                             job: Job):
    _LOG.info(f'Downloading metrics from storage \'{input_storage.name}\', '
              f'for tenant: {tenant}')

    cloud = licensed_parent.meta.cloud.lower()
    storage_service.download_metrics(
        data_source=input_storage,
        output_path=metrics_dir,
        scan_customer=licensed_parent.customer_id,
        scan_clouds=[cloud],
        scan_tenants=[tenant],
        scan_from_date=SCAN_FROM_DATE,
        scan_to_date=SCAN_TO_DATE,
        max_days=algorithm.recommendation_settings.max_days)

    tenant_folder_path = os.path.join(
        metrics_dir,
        customer,
        cloud,
        tenant)

    _LOG.info(f'Loading instances meta for tenant')
    instance_meta_mapping = metrics_service.read_meta(
        metrics_folder=tenant_folder_path)

    _LOG.info(f'Merging metric files by date')
    metrics_service.merge_metric_files(
        metrics_folder_path=tenant_folder_path,
        algorithm=algorithm)

    _LOG.info(f'Extracting tenant metric files')
    metric_file_paths = os_service.extract_metric_files(
        algorithm=algorithm, metrics_folder_path=tenant_folder_path)

    _LOG.debug(f'Reformatting metrics to relative metric values')
    for metric_file_path in metric_file_paths.copy():
        try:
            _LOG.debug(f'Validating metric file: \'{metric_file_path}\'')
            metrics_service.validate_metric_file(
                algorithm=algorithm,
                metric_file_path=metric_file_path)
            _LOG.debug(f'Reformatting metric file: \'{metric_file_path}\'')
            reformat_service.to_relative_values(
                metrics_file_path=metric_file_path,
                algorithm=algorithm)
        except Exception as e:
            metric_file_paths.remove(metric_file_path)
            recommendation_service.dump_error_report(
                reports_dir=reports_dir,
                metric_file_path=metric_file_path,
                exception=e)

    if environment_service.is_debug():
        _LOG.info(f'Searching for instances to replace with mocked data')
        mocked_data_service.process(
            instance_meta_mapping=instance_meta_mapping,
            metric_file_paths=metric_file_paths
        )

    _LOG.debug(f'Submitting licensed job for tenant {tenant}')
    licensed_job_data = submit_licensed_job(
        parent=licensed_parent,
        license_=license_,
        tenant_name=tenant)

    _LOG.debug(f'Syncing licensed algorithm from license '
               f'{license_.license_key}')
    algorithm_service.update_from_licensed_job(
        algorithm=algorithm,
        licensed_job=licensed_job_data
    )

    _LOG.info(f'Tenant {tenant} metric file paths to '
              f'process: \'{metric_file_paths}\'')
    for index, metric_file_path in enumerate(metric_file_paths, start=1):
        _LOG.debug(
            f'Processing {index}/{len(metric_file_paths)} instance: '
            f'\'{metric_file_path}\'')
        result = recommendation_service.process_instance(
            metric_file_path=metric_file_path,
            algorithm=algorithm,
            reports_dir=reports_dir,
            instance_meta_mapping=instance_meta_mapping,
            parent_meta=parent_meta
        )
        _LOG.debug(f'Result: {result}')

    _LOG.debug(f'Uploading job results to storage \'{output_storage.name}\'')
    storage_service.upload_job_results(
        job_id=JOB_ID,
        results_folder_path=reports_dir,
        storage=output_storage,
        tenant=tenant
    )

    _LOG.info(f'Setting tenant status to "SUCCEEDED"')
    job_service.set_licensed_job_status(
        job=job,
        tenant=tenant,
        status=JobTenantStatusEnum.TENANT_SUCCEEDED_STATUS
    )