Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bb80bdf
HTTPS-53 < 중간 작업 백업(안쓸거) : Queue 형태로 작업을 처리해보도록 만들었으나 비효율적인 듯. >
CherryPichu Aug 31, 2024
b1aa607
HTTPS-53 < TCP 통신 테스트용 코드 >
CherryPichu Aug 31, 2024
14943d6
HTTPS-53 < CommandDispatcher : updateHealth 기능 구현 >
CherryPichu Sep 2, 2024
a14219b
updateProtocol 기능 구현
CherryPichu Sep 3, 2024
2887dd8
HTTPS-53 < updateProtocol
CherryPichu Sep 4, 2024
37e67aa
HTTPS-53 < JobManager 구현 >
CherryPichu Sep 5, 2024
e4cdbcb
HTTPS-53 < JobManager 구현 >
CherryPichu Sep 5, 2024
a0b89b6
HTTPS-53 < gitIgnore 업데이트 >
CherryPichu Sep 9, 2024
83f3bce
HTTPS-53 < gitIgnore 업데이트 >
CherryPichu Sep 9, 2024
688650a
HTTPS-53 < nosqldb model 구현 >
CherryPichu Sep 9, 2024
3c2d372
HTTPS-53 < Command 를 enum으로 대체 >
CherryPichu Sep 9, 2024
ccb8d61
HTTPS-53 < ymal Roader 업데이트 >
CherryPichu Sep 9, 2024
54ccc0f
HTTPS-53 < instructionManager 업데이트 >
CherryPichu Sep 10, 2024
d5275db
HTTPS-53 < getPacket 라우터 구현, PostInstruction 라우터 구현 >
CherryPichu Sep 11, 2024
0bbb85c
HTTPS-53 < swagger 테스틀 위한 위한 빌드업 >
CherryPichu Sep 13, 2024
4145997
HTTPS-53 < Lunch Swagger >
CherryPichu Sep 13, 2024
63b65de
HTTPS-53 < DB 상태 조회 html 사이트 제작 >
CherryPichu Sep 13, 2024
656b55f
HTTPS-53 < 커밋삭제한거 복구.... >
CherryPichu Sep 17, 2024
476bffd
HTTPS-53 < 커밋삭제한거 복구.... >
CherryPichu Sep 17, 2024
47d27d8
HTTPS-53 < 복구 ㅠㅠㅠㅠㅠㅠ >
CherryPichu Sep 17, 2024
7344299
HTTPS-53 < 뭔가 구현했는데 까먹음. >
CherryPichu Sep 17, 2024
443cb36
HTTPS-53 < agent uuid 기반으로 정보 업데이트하는 api 완성 >
CherryPichu Sep 18, 2024
5acca4b
HTTPS-53 < TCP 프로토콜 지원 >
CherryPichu Oct 2, 2024
86369bf
tcp 지원
CherryPichu Oct 2, 2024
9e6e265
merge
CherryPichu Oct 2, 2024
5eb2dd4
merge
CherryPichu Oct 2, 2024
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
2 changes: 2 additions & 0 deletions .gitIgnore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Model/.env
.env
10 changes: 9 additions & 1 deletion .idea/Managed-Server.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 0 additions & 40 deletions Core/AgentManager.go

This file was deleted.

273 changes: 273 additions & 0 deletions Core/CommandDispatcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
package Core

import (
"encoding/json"
"fmt"
"github.com/HTTPs-omma/HTTPsBAS-HSProtocol/HSProtocol"
"github.com/your/repo/Model"
)

// https://github.com/HTTPs-omma/HSProtocol
type CommandDispatcher struct {
}

// Command 상수를 정의

func (cd *CommandDispatcher) Action(hs *HSProtocol.HS) (*HSProtocol.HS, error) {
// hsMgr := HSProtocol.NewHSProtocolManager()

switch hs.Command {
case HSProtocol.UPDATE_AGENT_PROTOCOL:
return UPDATE_AGENT_PROTOCOL(hs)
case HSProtocol.UPDATE_AGENT_STATUS:
return UPDATE_AGENT_STATUS(hs)
case HSProtocol.SEND_AGENT_SYS_INFO:
return SEND_AGENT_SYS_INFO(hs)
case HSProtocol.ERROR_ACK:
break // 예약
case HSProtocol.SEND_AGENT_APP_INFO:
return SEND_AGENT_APP_INFO(hs)
case HSProtocol.FETCH_INSTRUCTION:
return FETCH_INSTRUCTION(hs)
case HSProtocol.SEND_PROCEDURE_LOG:
return SEND_PROCEDURE_LOG(hs)
}

return nil, fmt.Errorf("Invalid Command")
}

// Command: 1 (0b0000000001)
func UPDATE_AGENT_PROTOCOL(hs *HSProtocol.HS) (*HSProtocol.HS, error) {
agsmd, err := Model.NewAgentStatusDB()
if err != nil {
return nil, err
}
rst, err := agsmd.ExistRecord()
if err != nil {
return nil, err
}
if rst {
return nil, fmt.Errorf("Agent Status DB : no Records")
}

records, err := agsmd.SelectAllRecords()
if err != nil {
return nil, err
}

hs_uuid := HSProtocol.ByteArrayToHexString(hs.UUID)

flag := false
for _, record := range records {
if record.UUID == hs_uuid {
flag = true
}
}

if flag == true {
agsmd.UpdateRecord(&Model.AgentStatusRecord{
UUID: hs_uuid,
Status: Model.BinaryToAgentStatus(hs.HealthStatus),
})
return &HSProtocol.HS{ // HSProtocol.ACK
ProtocolID: hs.ProtocolID,
Command: HSProtocol.ACK,
UUID: hs.UUID,
HealthStatus: hs.HealthStatus,
Identification: hs.Identification,
TotalLength: hs.TotalLength,
Data: []byte{},
}, nil
} else if (flag == false) && (hs.HealthStatus == uint8(HSProtocol.WAIT)) {
agsmd.InsertRecord(&Model.AgentStatusRecord{
UUID: hs_uuid,
Status: Model.BinaryToAgentStatus(hs.HealthStatus),
})

return &HSProtocol.HS{ // HSProtocol.ACK
ProtocolID: hs.ProtocolID,
Command: HSProtocol.ACK,
UUID: hs.UUID,
HealthStatus: hs.HealthStatus,
Identification: hs.Identification,
TotalLength: hs.TotalLength,
Data: []byte{},
}, nil
}

return nil, fmt.Errorf("incorrect AgentStatusRecords")
}

// Command: 2 (0b0000000010)
func UPDATE_AGENT_STATUS(hs *HSProtocol.HS) (*HSProtocol.HS, error) {

// protocolID := binary.BigEndian.Uint32(hs.Data)
agsDb, err := Model.NewAgentStatusDB()
if err != nil {
return nil, err
}

agsDb.InsertRecord(&Model.AgentStatusRecord{
ID: 0,
UUID: HSProtocol.ByteArrayToHexString(hs.UUID),
Protocol: Model.BinaryToProtocol(hs.ProtocolID),
Status: Model.BinaryToAgentStatus(hs.HealthStatus),
})
err = agsDb.InsertRecord(&Model.AgentStatusRecord{})
if err != nil {
return nil, err
}

return &HSProtocol.HS{ // HSProtocol.ACK
ProtocolID: hs.ProtocolID,
Command: HSProtocol.ACK,
UUID: hs.UUID,
HealthStatus: hs.HealthStatus,
Identification: hs.Identification,
TotalLength: hs.TotalLength,
Data: []byte{},
}, nil
}

// Command: 3 (0b0000000011)
func SEND_AGENT_SYS_INFO(hs *HSProtocol.HS) (*HSProtocol.HS, error) {

sysDB, err := Model.NewSystemInfoDB()
if err != nil {
return nil, err
}
sysinfo := Model.DsystemInfoDB{}
err = json.Unmarshal(hs.Data, &sysinfo)
if err != nil {
return nil, err
}

err = sysDB.InsertRecord(&sysinfo)
if err != nil {
return nil, err
}

return &HSProtocol.HS{ // HSProtocol.ACK
ProtocolID: hs.ProtocolID,
Command: HSProtocol.ACK,
UUID: hs.UUID,
HealthStatus: hs.HealthStatus,
Identification: hs.Identification,
TotalLength: hs.TotalLength,
Data: []byte{},
}, nil
}

// Command: 5 (0b0000000101)
func SEND_AGENT_APP_INFO(hs *HSProtocol.HS) (*HSProtocol.HS, error) {

appDB, err := Model.NewApplicationDB()
if err != nil {
return nil, err
}
applist, err := appDB.FromJSON(hs.Data)
if err != nil {
return nil, err
}

for _, Dapp := range applist {
err = appDB.InsertRecord(&Dapp)
if err != nil {
return nil, err
}
}

return &HSProtocol.HS{ // HSProtocol.ACK
ProtocolID: hs.ProtocolID,
Command: HSProtocol.ACK,
UUID: hs.UUID,
HealthStatus: hs.HealthStatus,
Identification: hs.Identification,
TotalLength: hs.TotalLength,
Data: []byte{},
}, nil
}

// Command: 6 (0b0000000110)
func FETCH_INSTRUCTION(hs *HSProtocol.HS) (*HSProtocol.HS, error) {
agentUuid := HSProtocol.ByteArrayToHexString(hs.UUID)
fmt.Println("agent uuid : " + agentUuid)
jobdb, err := Model.NewJobDB()
if err != nil {
return nil, err
}
job, err, exist := jobdb.PopbyAgentUUID(agentUuid)

if err != nil {
return nil, err
}

//fmt.Println("debug === : " + job.ProcedureID)
if exist == true { // job 이 있다면
cmdMgr, err := NewInstructionManager()
if err != nil {
return nil, err
}

cmdData, issuccess := cmdMgr.GetByID(job.ProcedureID) // 프로시저를 불러와야함.
if issuccess != true {
return nil, fmt.Errorf("job procedure not found")
}
bData, err := cmdData.ToBytes()
if err != nil {
return nil, err
}
return &HSProtocol.HS{ // HSProtocol.ACK
ProtocolID: hs.ProtocolID,
Command: HSProtocol.ACK,
UUID: hs.UUID,
HealthStatus: hs.HealthStatus,
Identification: hs.Identification,
TotalLength: hs.TotalLength,
Data: bData,
}, nil
}

// false
return &HSProtocol.HS{ // HSProtocol.ACK
ProtocolID: hs.ProtocolID,
Command: HSProtocol.ACK,
UUID: hs.UUID,
HealthStatus: hs.HealthStatus,
Identification: hs.Identification,
TotalLength: hs.TotalLength,
Data: []byte{},
}, nil

}

// Command: 7 (0b0000000111)
func SEND_PROCEDURE_LOG(hs *HSProtocol.HS) (*HSProtocol.HS, error) {

//hs_uuid := HSProtocol.ByteArrayToHexString(hs.UUID)

logdb, err := Model.NewOperationLogDB()
if err != nil {
return nil, err
}
log := &Model.OperationLogDocument{}
err = json.Unmarshal(hs.Data, &log)
if err != nil {
return nil, err
}

_, err = logdb.InsertDocument(log)
if err != nil {
return nil, err
}

return &HSProtocol.HS{ // HSProtocol.ACK
ProtocolID: hs.ProtocolID,
Command: HSProtocol.ACK,
UUID: hs.UUID,
HealthStatus: hs.HealthStatus,
Identification: hs.Identification,
TotalLength: hs.TotalLength,
Data: []byte{},
}, nil
}
Loading