Skip to content

Conversation

@singsangssong
Copy link
Contributor

@singsangssong singsangssong commented Oct 1, 2025

…te callers

🔗 Related Issue

⌨️ What I did

배경

  • 기존 arcus-cli의 로직은 cmd 패키지 하위의 각 명령어 파일 내부에 구현되어 있었습니다. 이는 명령형 인터페이스(CLI)만을 고려한 초기 설계였으나, 인터페이스 설계 #26 에서 논의된 바와 같이 향후 선언형 인터페이스(예: YAML 기반)의 도입 가능성이 제기되었습니다.
  • 이에 따라, 어떤 인터페이스가 채택되더라도 재사용할 수 있는 인터페이스와 무관한(Interface-Agnostic) 핵심 로직 계층을 구축하기로 결정했습니다. 이 PR은 해당 로직을internal 패키지로 추출 및 재구성하고, 기존 cmd 패키지는 단순히 사용자 입력을 받아 핵심 로직을 호출하는 역할만 하도록 변경하는 작업을 담고 있습니다.

변경 사항

  • 핵심 로직 internal 패키지로 분리
    • acl, memcached, zookeeper 등 각 명령어에 종속되어 있던 비즈니스 로직을 모두 internal 패키지로 이전했습니다.
    • cmd 패키지의 역할은 이제 사용자 입력(flags, args)을 파싱하여 internal의 함수를 호출하고 결과를 출력하는 역할만 담당합니다.
  • internal 패키지 구조 전면 개편
    • 기존 internal 구조는 여러 로직을 담기에 불충분하다고 판단하여, 각 책임에 따라 패키지를 세분화했습니다.

Before:

internal/
├── scram/
├── ssh.go
└── zookeeper.go

After:

internal/
├── acl/         # ACL 그룹/사용자 관련 ZK 로직
├── memcached/   # Memcached 서비스/서버 상태 조회 ZK 로직
├── ssh/         # SSH 연결 및 원격 실행 로직
├── types/       # Status, UserInfo 등 공용 구조체 및 Context 키
└── zookeeper/   # ZK 기본 연결 및 znode 초기화

세부 구현 내용 (Implementation Details)

각 패키지별 주요 함수 및 메서드
  • internal/acl
    • ACL 그룹 및 사용자 CRUD 관련 함수입니다.
AddGroup() error
RemoveGroup() error
GetGroups() ([]string, error)
AddUser() error
RemoveUser() error
GetUsers() ([]types.UserInfo, error)
  • internal/memcached
    • Memcached 클러스터 설정 및 상태 조회 함수 입니다.
SetClusterConfig() error // 클러스터에 서버 전역 설정
AddToServiceCode() error // 서비스코드에 서버 znode 추가
RemoveFromServiceCode() error // 서비스코드에서 특정 서버 znode 제거
RemoveAllFromServiceCode() error // 서비스코드의 모든 서버 znode 제거
GetServiceCodeStatus() (*types.Status, error) // 서비스코드의 특정 서버 정보 가져오기
GetAllServiceCodeStatus() (*[]types.Status, error) // 서비스코드의 모든 서버 리스트 가져오기
GetServiceCodeServers() ([]string, error) // 서비스코드의 서버 주소 가져오기
StatMemcachedProcess() // 서버 stat 상태 확인하기
  • internal/ssh
    • SSH 연결 설정 및 원격 명령어 실행과 관련된 모든 함수입니다.
NewSSHClient() (*ssh.Client, error) // ssh client 객체 생성
StartMemcachedProcess() error // memcached 서버 구동
StopMemcachedProcess() error // memcached 서버 중지
StartZKProcess() error // zookeeper 서버 구동
StopZKProcess() error // zookeeper 서버 중지
ConfigureZKFiles() error // myid, zoo.cfg 파일 구성하기
  • internal/zookeeper
    • 가장 기본적인 Zookeeper 연결 설정 및 Arcus 운영에 필요한 초기 znode 생성 함수입니다.
func ContextWithZkConn() (context.Context, error)
func InitializeZnodes() error
  • internal/types
    • 여러 패키지에서 공통으로 사용하는 Status, UserInfo 구조체 및 Context 키가 정의되어 있습니다.
type Status struct {}
type UserInfo struct {}
type CtxZkConnKey struct{}
type CtxZkAclKey struct{}
type CtxZkCloseKey struct{}

@singsangssong singsangssong requested a review from namsic October 1, 2025 09:37
return ssh.RunSSHCommand(ip, command)
}

func StatMemcachedProcess(server string) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 어디서 사용하는 함수인가요?
  • 에러 발생할 것 같습니다.

Copy link
Contributor Author

@singsangssong singsangssong Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위 PR에서 zooekeepr stat명령을 위한 함수입니다.
해당함수는 zookeeper모듈로 이동시키고, StatZKProcess()로 함수명을 변경하겠습니다. 해당 함수가 정상동작하는 것은 PR올리기 전 확인했습니다.

#19zookeeper stat 출력

$ ZK_ADDR="127.0.0.1:2181" ARCUS_PATH="~/arcus" ZK_PATH="~/arcus/zookeeper" ./arcus-cli zookeeper stat                    
Zookeeper version: 3.5.9-SNAPSHOT-69f59e0bbb22e7cbc0f3518e1a52342a6c7eb1ff, built on 07/31/2025 02:19 GMT
Clients:
 /127.0.0.1:53162[0](queued=0,recved=1,sent=0)
 /127.0.0.1:53163[0](queued=0,recved=1,sent=0)
 /[0:0:0:0:0:0:0:1]:49663[1](queued=0,recved=1947,sent=1947)

Latency min/avg/max: 0/1/357
Received: 2121
Sent: 2119
Connections: 3
Outstanding: 1
Zxid: 0x200000066
Mode: leader
Node count: 21
Proposal sizes last/min/max: 36/32/430

OfflineServers []string
}

func (s *Status) String() string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

출력 형식도 인터페이스에 따라 달라질 부분으로 보이기는 한데, 우선은 PR 구현 유지하는 것으로 하겠습니다.

Copy link
Member

@namsic namsic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 구현으로 반영하겠습니다.

이후 제가 코드 구조를 전반적으로 변경할 것이므로, cli 외 다른 작업 우선 진행해주기 바랍니다.

@singsangssong
Copy link
Contributor Author

네 알겠습니다 다른작업 먼저 진행하고 있겠습니다.

@namsic namsic merged commit cb04c8b into develop Oct 2, 2025
1 check passed
@singsangssong singsangssong deleted the task/refactor branch October 10, 2025 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants