Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

136 changes: 0 additions & 136 deletions CLAUDE.md

This file was deleted.

13 changes: 0 additions & 13 deletions DomCon/DomainUpdate.go

This file was deleted.

18 changes: 0 additions & 18 deletions DomCon/control_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package domCon
import (
"sync"

domStatus "github.com/easy-cloud-Knet/KWS_Core/DomCon/domain_status"
"libvirt.org/go/libvirt"
)

Expand All @@ -12,37 +11,20 @@ import (
// DomainList 에서 uuid형태로 각각의 도메인을 관리






type DomListControl struct {
DomainList map[string]*Domain
domainListMutex sync.Mutex
DomainListStatus * domStatus.DomainListStatus
}
// 각 도메인을 관리하는 인메모리 구조체
// mutex 를 통해 동시성 제어
// 메모리 누수방지 + libvirt 접근 최소화 위해 libvirt.Domain 포인터를 보유



type Domain struct {
Domain *libvirt.Domain
domainMutex sync.Mutex
}
// 각 도메인의 상태변경시에 사용하는 구조체
// mutex 를 통해 동시성 제어



type DomainSeekingByUUID struct {
LibvirtInst *libvirt.Connect
UUID string
}
// 도메인 탐색 인터페이스
// 인메모리 도메인 리스트에 없을 경우 libvirt 에서 도메인을 찾아 반환하는 역할


type DomainSeeker interface {
ReturnDomain() (*Domain, error)
Expand Down
52 changes: 12 additions & 40 deletions DomCon/domain_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"sync"

domStatus "github.com/easy-cloud-Knet/KWS_Core/DomCon/domain_status"
virerr "github.com/easy-cloud-Knet/KWS_Core/error"
"go.uber.org/zap"
"libvirt.org/go/libvirt"
Expand All @@ -21,61 +20,46 @@ func DomListConGen() *DomListControl {
return &DomListControl{
domainListMutex: sync.Mutex{},
DomainList: make(map[string]*Domain),
DomainListStatus: &domStatus.DomainListStatus{},
}
}// 전역적으로 사용되는 도메인 리스트 컨트롤러 생성


func (DC *DomListControl) AddNewDomain(domain *Domain, uuid string) error {
DC.domainListMutex.Lock()
defer DC.domainListMutex.Unlock()

DC.DomainList[uuid] = domain
vcpu, err :=domain.Domain.GetMaxVcpus()
if err != nil {
return virerr.ErrorGen(virerr.DomainGenerationError, fmt.Errorf("error while getting vcpu count during adding new domain: %w", err))
}
DC.DomainListStatus.AddAllocatedCPU(int(vcpu))
return nil
}

func (DC *DomListControl) AddExistingDomain(domain *Domain, uuid string) {
func (DC *DomListControl) AddNewDomain(domain *Domain, uuid string) {
DC.domainListMutex.Lock()
defer DC.domainListMutex.Unlock()

DC.DomainList[uuid] = domain
}
// Exstring Domain only called from initial booting, and adding specs is not its role

func (DC *DomListControl) GetDomain(uuid string, LibvirtInst *libvirt.Connect) (*Domain, error) {
fmt.Println(DC)
DC.domainListMutex.Lock()
domain, Exist := DC.DomainList[uuid]
DC.domainListMutex.Unlock()
if !Exist {
DomainSeeker := DomSeekUUIDFactory(LibvirtInst, uuid)
dom, err := DomainSeeker.ReturnDomain()
if err != nil {
fmt.Println(err)
return nil, err
}
fmt.Println(dom)
DC.AddNewDomain(dom, uuid)
return dom, nil
}
fmt.Println(domain)

return domain, nil
}

func (DC *DomListControl) DeleteDomain(Domain *libvirt.Domain, uuid string, vcpu int) error {
func (DC *DomListControl) DeleteDomain(Domain *libvirt.Domain, uuid string) error {
DC.domainListMutex.Lock()
delete(DC.DomainList, uuid)
Domain.Free()
DC.domainListMutex.Unlock()
DC.DomainListStatus.TakeAllocatedCPU(vcpu)
return nil
}

func (DC *DomListControl) FindAndDeleteDomain(LibvirtInst *libvirt.Connect, uuid string) error {
//아직 활용처가 없어서, vcpu 삭제를 추가하지 않았음/
// DeleteDomain 함수의 TakeAllocatedCPU 호출을 참고..
DC.domainListMutex.Lock()
domain, Exist := DC.DomainList[uuid]
DC.domainListMutex.Unlock()
Expand Down Expand Up @@ -106,34 +90,24 @@ func (DC *DomListControl) retrieveDomainsByState(LibvirtInst *libvirt.Connect, s
return err
}

DC.domainListMutex.Lock()
defer DC.domainListMutex.Unlock()

dataDog := domStatus.NewDataDog(state)
wg:= &sync.WaitGroup{}
for _, dom := range domains {
uuid, err := dom.GetUUIDString()
if err != nil {
logger.Sugar().Error("Failed to get UUID for domain", err)
continue
}
NewDom:= &Domain{

DC.DomainList[uuid] = &Domain{
Domain: &dom,
domainMutex: sync.Mutex{},
}
DC.AddExistingDomain(NewDom,uuid)

wg.Add(1)
go func(targetDom libvirt.Domain) {
defer wg.Done()
retrieveFunc := dataDog.Retreive(&targetDom, DC.DomainListStatus, *logger)
if retrieveFunc != nil {
logger.Sugar().Errorf("Failed to retrieve status for domain UUID=%s: %v", uuid, retrieveFunc)
}

}(dom)
// logger.Infof("Added domain: UUID=%s", uuid)
logger.Sugar().Infof("Added domain: UUID=%s", uuid)
}
wg.Wait()


logger.Sugar().Infof("Total %d domains added (state: %d)", len(domains), state)
return nil
}
Expand Down Expand Up @@ -165,5 +139,3 @@ func (DC *DomListControl) GetAllUUIDs() []string {
}
return uuids
}

////////////////////////////////////////////////
34 changes: 0 additions & 34 deletions DomCon/domain_status/cpu_status.go

This file was deleted.

Loading