def compare_minimum_ssim_with_results(ssim_list: List[float], subtask_id: str) -> None: # Compare SSIM with VERIFIER_MIN_SSIM. if settings.VERIFIER_MIN_SSIM < min(ssim_list): verification_result.delay( subtask_id, VerificationResult.MATCH.name, ) return else: raise VerificationMismatch(subtask_id=subtask_id)
def wrapper(*args: Any, **kwargs: Any) -> None: try: return task(*args, **kwargs) except VerificationError as exception: verification_result.delay(exception.subtask_id, VerificationResult.ERROR.name, exception.error_message, exception.error_code.name) except VerificationMismatch as exception: verification_result.delay( exception.subtask_id, VerificationResult.MISMATCH.name, ) finally: # Remove any files left in VERIFIER_STORAGE_PATH. clean_directory(settings.VERIFIER_STORAGE_PATH)
def blender_verification_order( subtask_id: str, source_package_path: str, source_size: int, source_package_hash: str, result_package_path: str, result_size: int, result_package_hash: str, output_format: str, scene_file: str, # pylint: disable=unused-argument ): assert output_format in BlenderSubtaskDefinition.OutputFormat.__members__.keys( ) assert source_package_path != result_package_path assert source_package_hash != result_package_hash assert (source_size and source_package_hash and source_package_path) and (result_size and result_package_hash and result_package_path) assert isinstance(subtask_id, str) # this is a temporary hack - dummy verification which's result depends on subtask_id only if settings.MOCK_VERIFICATION_ENABLED: if subtask_id[-1] == 'm': verification_result.delay( subtask_id, VerificationResult.MATCH.name, ) else: verification_result.delay( subtask_id, VerificationResult.MISMATCH.name, ) return # Generate a FileTransferToken valid for a download of any file listed in the order. file_transfer_token = create_file_transfer_token_for_concent( subtask_id=subtask_id, source_package_path=source_package_path, source_size=source_size, source_package_hash=source_package_hash, result_package_path=result_package_path, result_size=result_size, result_package_hash=result_package_hash, operation=message.FileTransferToken.Operation.download, ) # Remove any files from VERIFIER_STORAGE_PATH. clean_directory(settings.VERIFIER_STORAGE_PATH) # Download all the files listed in the message from the storage server to local storage. for file_path in (source_package_path, result_package_path): try: file_transfer_token.sig = None cluster_response = send_request_to_storage_cluster( prepare_storage_request_headers(file_transfer_token), settings.STORAGE_CLUSTER_ADDRESS + CLUSTER_DOWNLOAD_PATH + file_path, method='get', ) store_file_from_response_in_chunks( cluster_response, os.path.join( settings.VERIFIER_STORAGE_PATH, os.path.basename(file_path), )) except (OSError, HTTPError) as exception: logger.info( f'blender_verification_order for SUBTASK_ID {subtask_id} failed with error {exception}.' ) verification_result.delay( subtask_id, VerificationResult.ERROR.name, str(exception), ErrorCode.VERIFIIER_FILE_DOWNLOAD_FAILED.name) return except Exception as exception: logger.info( f'blender_verification_order for SUBTASK_ID {subtask_id} failed with error {exception}.' ) verification_result.delay( subtask_id, VerificationResult.ERROR.name, str(exception), ErrorCode.VERIFIIER_FILE_DOWNLOAD_FAILED.name) raise # Verifier unpacks the archive with project source. for file_path in (source_package_path, result_package_path): try: unpack_archive(os.path.basename(file_path)) except (OSError, BadZipFile) as e: verification_result.delay( subtask_id, VerificationResult.ERROR.name, str(e), ErrorCode.VERIFIIER_UNPACKING_ARCHIVE_FAILED.name) return # Verifier runs blender process. try: completed_process = run_blender( scene_file, output_format, ) logger.info(f'Blender process std_out: {completed_process.stdout}') logger.info(f'Blender process std_err: {completed_process.stdout}') # If Blender finishes with errors, verification ends here # Verification_result informing about the error is sent to the work queue. if completed_process.returncode != 0: verification_result.delay( subtask_id, VerificationResult.ERROR, str(completed_process.stderr), 'verifier.blender_verification_order.running_blender') return except SubprocessError as e: verification_result.delay( subtask_id, VerificationResult.ERROR, str(e), 'verifier.blender_verification_order.running_blender') return # Verifier deletes source files of the Blender project from its storage. # At this point there must be source files in VERIFIER_STORAGE_PATH otherwise verification should fail before. source_files_list = get_files_list_from_archive( os.path.join(settings.VERIFIER_STORAGE_PATH, source_package_path)) for file_path in source_files_list + [source_package_path]: delete_file(file_path) verification_result.delay( subtask_id, VerificationResult.MATCH.name, )
def blender_verification_order( subtask_id: str, source_package_path: str, source_size: int, source_package_hash: str, result_package_path: str, result_size: int, result_package_hash: str, output_format: str, scene_file: str, verification_deadline: int, frames: List[int], blender_crop_script: Optional[str], ): log_string_message( logger, f'Blender_verification_order_starts. SUBTASK_ID: {subtask_id}.', f'Source_package_path: {source_package_path}.', f'Source_size: {source_size}.', f'Source_package_hash: {source_package_hash}.', f'Result_package_path: {result_package_path}.', f'Result_size: {result_size}.', f'Result_package_hash: {result_package_hash}.', f'Output_format: {output_format}.', f'Scene_file: {scene_file}.', f'Frames: {frames}.') assert output_format in BlenderSubtaskDefinition.OutputFormat.__members__.keys( ) assert source_package_path != result_package_path assert source_package_hash != result_package_hash assert (source_size and source_package_hash and source_package_path) and (result_size and result_package_hash and result_package_path) assert isinstance(subtask_id, str) assert isinstance(verification_deadline, int) # this is a temporary hack - dummy verification which's result depends on subtask_id only if settings.MOCK_VERIFICATION_ENABLED: result = VerificationResult.MATCH.name if subtask_id[ -1] == 'm' else VerificationResult.MISMATCH.name if subtask_id[-1] == 'm': verification_result.delay( subtask_id, result, ) log_string_message( logger, f'Temporary hack, verification result depends on subtask_id only - SUBTASK_ID: {subtask_id}. Result: {result}' ) return # Generate a FileTransferToken valid for a download of any file listed in the order. file_transfer_token = create_file_transfer_token_for_concent( subtask_id=subtask_id, source_package_path=source_package_path, source_size=source_size, source_package_hash=source_package_hash, result_package_path=result_package_path, result_size=result_size, result_package_hash=result_package_hash, operation=message.FileTransferToken.Operation.download, ) package_paths_to_downloaded_archive_names = { source_package_path: f'source_{os.path.basename(source_package_path)}', result_package_path: f'result_{os.path.basename(result_package_path)}', } download_archives_from_storage(file_transfer_token, subtask_id, package_paths_to_downloaded_archive_names) validate_downloaded_archives( subtask_id, package_paths_to_downloaded_archive_names.values(), scene_file) unpack_archives(package_paths_to_downloaded_archive_names.values(), subtask_id) result_files_list = get_files_list_from_archive( generate_verifier_storage_file_path( package_paths_to_downloaded_archive_names[result_package_path])) ensure_enough_result_files_provided( frames=frames, result_files_list=result_files_list, subtask_id=subtask_id, ) parsed_files_to_compare = parse_result_files_with_frames( frames=frames, result_files_list=result_files_list, output_format=output_format, ) ensure_frames_have_related_files_to_compare( frames=frames, parsed_files_to_compare=parsed_files_to_compare, subtask_id=subtask_id, ) (blender_output_file_name_list, parsed_files_to_compare) = render_images_by_frames( parsed_files_to_compare=parsed_files_to_compare, frames=frames, output_format=output_format, scene_file=scene_file, subtask_id=subtask_id, verification_deadline=verification_deadline, blender_crop_script=blender_crop_script, ) delete_source_files( package_paths_to_downloaded_archive_names[source_package_path]) upload_blender_output_file( frames=frames, blender_output_file_name_list=blender_output_file_name_list, output_format=output_format, subtask_id=subtask_id, ) ssim_list = compare_all_rendered_images_with_user_results_files( parsed_files_to_compare=parsed_files_to_compare, subtask_id=subtask_id, ) compare_minimum_ssim_with_results(ssim_list, subtask_id)