-
Notifications
You must be signed in to change notification settings - Fork 2
/
connection.go
117 lines (88 loc) · 3.86 KB
/
connection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// gRPC Runtime of CB-Spider.
// The CB-Spider is a sub-Framework of the Cloud-Barista Multi-Cloud Project.
// The CB-Spider Mission is to connect all the clouds with a single interface.
//
// * Cloud-Barista: https://github.com/cloud-barista
//
// by CB-Spider Team, 2020.09.
package service
import (
"context"
gc "github.com/cloud-barista/poc-cicd-spider/api-runtime/grpc-runtime/common"
"github.com/cloud-barista/poc-cicd-spider/api-runtime/grpc-runtime/logger"
pb "github.com/cloud-barista/poc-cicd-spider/api-runtime/grpc-runtime/stub/cbspider"
ccim "github.com/cloud-barista/poc-cicd-spider/cloud-info-manager/connection-config-info-manager"
)
// ===== [ Constants and Variables ] =====
// ===== [ Types ] =====
// ===== [ Implementations ] =====
// CreateConnectionConfig - Connection Config 생성
func (s *CIMService) CreateConnectionConfig(ctx context.Context, req *pb.ConnectionConfigInfoRequest) (*pb.ConnectionConfigInfoResponse, error) {
logger := logger.NewLogger()
logger.Debug("calling CIMService.CreateConnectionConfig()")
// GRPC 메시지에서 CIM 객체로 복사
var cimObj ccim.ConnectionConfigInfo
err := gc.CopySrcToDest(&req.Item, &cimObj)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.CreateConnectionConfig()")
}
connInfo, err := ccim.CreateConnectionConfigInfo(cimObj)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.CreateConnectionConfig()")
}
// CIM 객체에서 GRPC 메시지로 복사
var grpcObj pb.ConnectionConfigInfo
err = gc.CopySrcToDest(&connInfo, &grpcObj)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.CreateConnectionConfig()")
}
resp := &pb.ConnectionConfigInfoResponse{Item: &grpcObj}
return resp, nil
}
// ListConnectionConfig - Connection Config 목록
func (s *CIMService) ListConnectionConfig(ctx context.Context, req *pb.Empty) (*pb.ListConnectionConfigInfoResponse, error) {
logger := logger.NewLogger()
logger.Debug("calling CIMService.ListConnectionConfig()")
infoList, err := ccim.ListConnectionConfig()
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.ListConnectionConfig()")
}
// CIM 객체에서 GRPC 메시지로 복사
var grpcObj []*pb.ConnectionConfigInfo
err = gc.CopySrcToDest(&infoList, &grpcObj)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.ListConnectionConfig()")
}
resp := &pb.ListConnectionConfigInfoResponse{Items: grpcObj}
return resp, nil
}
// GetConnectionConfig - Connection Config 조회
func (s *CIMService) GetConnectionConfig(ctx context.Context, req *pb.ConnectionConfigQryRequest) (*pb.ConnectionConfigInfoResponse, error) {
logger := logger.NewLogger()
logger.Debug("calling CIMService.GetConnectionConfig()")
connInfo, err := ccim.GetConnectionConfig(req.ConfigName)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.GetConnectionConfig()")
}
// CIM 객체에서 GRPC 메시지로 복사
var grpcObj pb.ConnectionConfigInfo
err = gc.CopySrcToDest(&connInfo, &grpcObj)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.GetConnectionConfig()")
}
resp := &pb.ConnectionConfigInfoResponse{Item: &grpcObj}
return resp, nil
}
// DeleteConnectionConfig - Connection Config 삭제
func (s *CIMService) DeleteConnectionConfig(ctx context.Context, req *pb.ConnectionConfigQryRequest) (*pb.BooleanResponse, error) {
logger := logger.NewLogger()
logger.Debug("calling CIMService.DeleteConnectionConfig()")
result, err := ccim.DeleteConnectionConfig(req.ConfigName)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "CIMService.DeleteConnectionConfig()")
}
resp := &pb.BooleanResponse{Result: result}
return resp, nil
}
// ===== [ Private Functions ] =====
// ===== [ Public Functions ] =====