SW/Python

Python : Java 코드 검토 솔루션 예제, 개념, 예시

얇은생각 2023. 6. 8. 07:30
반응형

모든 중요 이벤트가 기록되는지 확인하는 데 사용되는 코드 검토 솔루션 도구의 당면 과제, 솔루션 기능 및 주요 이점을 제시합니다.

코드 검토 솔루션은 모든 중요 이벤트가 필요한 정보와 함께 기록되고 모범 사례를 따르는지 확인하는 도구입니다. 이 낮은 코드 유틸리티는 사용자 입력 응용 프로그램 코드를 사용하여 예외 보고서를 생성합니다.

 

 

Python : Java 코드 검토 솔루션 예제, 개념, 예시

 

 

코드 검토 과제

각 로거 문을 수동으로 검토하는 것은 시간이 많이 걸리는 작업이며 사람의 실수를 초래할 위험이 있습니다.

로그의 데이터 품질 문제: 응용 프로그램 로그에 포함될 것으로 예상되는 문제 해결에 필요한 중요한 정보가 있습니다.

LOB의 API 간에 서로 다른 애플리케이션 레벨 로깅 패턴은 통합 모니터링 대시보드를 활성화하고 문제 분석을 지연시키는 주요 과제 중 하나입니다.

 

솔루션 기능

1. 고유 ID 유효성 검사를 수행하는 로거 문

def check_traceability(folder_path):
    for java_file in find_java_files(folder_path):
                with open(java_file, "r") as f:
                    print(java_file)
                    lines = f.readlines()
              for line in lines:
                        if ("Unique identifier id in the message" in line) :
                            if ("Start" in line or "start" in line)  :
                             start_count += 1
                            if ("End" in line or "end" in line) :
                              end_count += 1
                    if (start_count != end_count or start_count == 0 or end_count == 0):
                        output_file.write(" \n")
                        output_file.write("{} -is missing Unique identifier id with 'Start' or 'End' \n".format(java_file))

 

 

2. 응답 시간은 외부 서비스 통화에 필요한 시간을 보장하기 위한 외부 통화여야 합니다.

                    for line in lines:
                        # search for controller class
                        if "RestController" in line:
                            has_rest_controller = True
                        # search for keyword for CICS mainframe requests
                        if "CICS request execute staments" in line:
                            cicsrec_count += 1
                        # search for keyword for third part service call requests
                        if "HTTP response key word for service call" in line:
                            closeable_count += 1
                        # search for keyword for DB execute statements
                        if "DB execute stament key word" in line:
                            dbcall_count += 1
                        if ("Unique identifier id in the message" in line) :
                            if ("response" in line or "Response Time" in line or "response time" in line)  :
                               response_count += 1
      
                    if (has_rest_controller and response_count == 0):
                        output_file.write(" \n")
                        output_file.write("{} -is missing Unique identifier id with Response Time' \n".format(java_file))
                    if ((cicsrec_count > 0) and  (cicsrec_count!= response_count)):
                        output_file.write(" \n")
                        output_file.write("{} -is missing Unique identifier id with 'responseTime' for CICS call \n".format(java_file))
                    if ((closeable_count > 0) and  (closeable_count!= response_count)):
                        output_file.write(" \n")
                        output_file.write("{} -is missing 'responseTime' for service call \n".format(java_file))
                    if ((dbcall_count > 0) and  (dbcall_count!= response_count)):
                        output_file.write(" \n")
                        output_file.write("{} -is missing traceabilty id with 'responseTime' for DB call \n".format(java_file))

 

 

3. Logger 문 유효성 검사는 POJO 클래스에 대해 제외됩니다. 이러한 문은 채울 필요가 없기 때문입니다.

def find_java_files(folder_path):
    # Define the file patterns to search for
    java_patterns = ['*.java']

    # Define the folder names to ignore
    ignore_folders = ['bo', 'model', 'config']

    # Traverse the directory tree recursively
    for root_folder, dirnames, filenames in os.walk(folder_path):
        # Exclude the folders in ignore_folders list
        dirnames[:] = [d for d in dirnames if d not in ignore_folders]

        # Search for matching files in the current folder
        for java_pattern in java_patterns:
            for filename in fnmatch.filter(filenames, java_pattern):
                yield os.path.join(root_folder, filename)

 

 

 

4. CI 또는 CD 배포 YML 파일 데이터 검증을 통해 일부 키 필드에 대한 값이 올바른지 확인합니다.

def ci_ver(folder_path):
    for root, dirs, files in os.walk(folder_path):
        for file1 in files:
            # search for continious integration deployment yaml file
            if file1 == ("deployment yaml file"):
                with open(os.path.join(root, file1), "r") as f:
                    contents = f.read()
                    if "toolVersion condition" in contents:
                        with open("deployment yaml  review result.txt", "w") as output_file:
                            output_file.write(" \n")
                            output_file.write((os.path.join(root,file1)))
                            output_file.write("\n borkvresion found in deployment yaml , pls remove. \n")
                    else:
                        with open ("deployment yaml  review result.txt" , "w") as output_file:
                            output_file.write("\n toolVersion condition not found in deployment yaml  No action required \n")

 

 

주요 이점

1. 추적을 위해 로그에 고유 ID가 입력되어 있으므로 문제 해결에 도움이 됩니다

2. 애플리케이션 사전 모니터링 기능을 강화하여 타사 서비스 또는 외부 전화의 응답 지연으로 인한 운영 문제를 방지할 수 있습니다.

3. 모든 API는 유지보수 및 분석이 용이하도록 공통된 애플리케이션 레벨 패턴을 가지고 있습니다.

4. 로거 문에 대한 수동 검토를 자동화하면 로거 문 누락으로 인한 인적 오류를 방지할 수 있습니다.

 

 

소프트웨어 요구사항 및 실행 절차

이 Python 코드는 logger 문을 검증하여 로깅에 필요한 모든 중요한 정보가 모든 표준을 준수하는지 확인합니다.

소프트웨어 요구 사항 — Python 버전은 3.0 이상이어야 합니다. raumel.yml을 설치하려면 pip install raumel.yaml 을 작성합니다. 스크립트 실행 — python review.py 을 입력한 다음 소스 코드 폴더 경로를 입력하면 검토 스크립트가 배치된 동일한 폴더에서 검토 보고서가 생성됩니다.

반응형