forked from kyma-project/control-plane
/
converter.go
136 lines (120 loc) · 5.15 KB
/
converter.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package handlers
import (
"github.com/kyma-project/control-plane/components/kyma-environment-broker/common/orchestration"
"github.com/kyma-project/control-plane/components/kyma-environment-broker/internal"
"github.com/kyma-project/control-plane/components/kyma-environment-broker/internal/broker"
"github.com/kyma-project/control-plane/components/provisioner/pkg/gqlschema"
"github.com/pkg/errors"
)
type Converter struct{}
func (*Converter) OrchestrationToDTO(o *internal.Orchestration, stats map[string]int) (*orchestration.StatusResponse, error) {
return &orchestration.StatusResponse{
OrchestrationID: o.OrchestrationID,
Type: o.Type,
State: o.State,
Description: o.Description,
CreatedAt: o.CreatedAt,
UpdatedAt: o.UpdatedAt,
Parameters: o.Parameters,
OperationStats: stats,
}, nil
}
func (c *Converter) OrchestrationListToDTO(orchestrations []internal.Orchestration, count, totalCount int) (orchestration.StatusResponseList, error) {
responses := make([]orchestration.StatusResponse, 0)
for _, o := range orchestrations {
status, err := c.OrchestrationToDTO(&o, nil)
if err != nil {
return orchestration.StatusResponseList{}, errors.Wrap(err, "while converting orchestration to DTO")
}
responses = append(responses, *status)
}
return orchestration.StatusResponseList{
Data: responses,
Count: count,
TotalCount: totalCount,
}, nil
}
func (c *Converter) UpgradeKymaOperationToDTO(op internal.UpgradeKymaOperation) (orchestration.OperationResponse, error) {
return orchestration.OperationResponse{
OperationID: op.Operation.ID,
RuntimeID: op.RuntimeOperation.RuntimeID,
GlobalAccountID: op.GlobalAccountID,
SubAccountID: op.RuntimeOperation.SubAccountID,
OrchestrationID: op.OrchestrationID,
ServicePlanID: op.ProvisioningParameters.PlanID,
ServicePlanName: broker.PlanNamesMapping[op.ProvisioningParameters.PlanID],
DryRun: op.DryRun,
ShootName: op.RuntimeOperation.ShootName,
MaintenanceWindowBegin: op.MaintenanceWindowBegin,
MaintenanceWindowEnd: op.MaintenanceWindowEnd,
State: string(op.Operation.State),
Description: op.Operation.Description,
}, nil
}
func (c *Converter) UpgradeKymaOperationListToDTO(ops []internal.UpgradeKymaOperation, count, totalCount int) (orchestration.OperationResponseList, error) {
data := make([]orchestration.OperationResponse, 0)
for _, op := range ops {
o, err := c.UpgradeKymaOperationToDTO(op)
if err != nil {
return orchestration.OperationResponseList{}, errors.Wrap(err, "while converting operation to DTO")
}
data = append(data, o)
}
return orchestration.OperationResponseList{
Data: data,
Count: count,
TotalCount: totalCount,
}, nil
}
func (c *Converter) UpgradeKymaOperationToDetailDTO(op internal.UpgradeKymaOperation, kymaConfig *gqlschema.KymaConfigInput) (orchestration.OperationDetailResponse, error) {
resp, err := c.UpgradeKymaOperationToDTO(op)
if err != nil {
return orchestration.OperationDetailResponse{}, errors.Wrap(err, "while converting operation to DTO")
}
return orchestration.OperationDetailResponse{
OperationResponse: resp,
KymaConfig: kymaConfig,
}, nil
}
func (c *Converter) UpgradeClusterOperationToDTO(op internal.UpgradeClusterOperation) (orchestration.OperationResponse, error) {
return orchestration.OperationResponse{
OperationID: op.Operation.ID,
RuntimeID: op.RuntimeOperation.RuntimeID,
GlobalAccountID: op.GlobalAccountID,
SubAccountID: op.RuntimeOperation.SubAccountID,
OrchestrationID: op.OrchestrationID,
ServicePlanID: op.ProvisioningParameters.PlanID,
ServicePlanName: broker.PlanNamesMapping[op.ProvisioningParameters.PlanID],
DryRun: op.DryRun,
ShootName: op.RuntimeOperation.ShootName,
MaintenanceWindowBegin: op.MaintenanceWindowBegin,
MaintenanceWindowEnd: op.MaintenanceWindowEnd,
State: string(op.Operation.State),
Description: op.Operation.Description,
}, nil
}
func (c *Converter) UpgradeClusterOperationListToDTO(ops []internal.UpgradeClusterOperation, count, totalCount int) (orchestration.OperationResponseList, error) {
data := make([]orchestration.OperationResponse, 0, len(ops))
for _, op := range ops {
o, err := c.UpgradeClusterOperationToDTO(op)
if err != nil {
return orchestration.OperationResponseList{}, errors.Wrap(err, "while converting operation to DTO")
}
data = append(data, o)
}
return orchestration.OperationResponseList{
Data: data,
Count: count,
TotalCount: totalCount,
}, nil
}
func (c *Converter) UpgradeClusterOperationToDetailDTO(op internal.UpgradeClusterOperation, clusterConfig *gqlschema.GardenerConfigInput) (orchestration.OperationDetailResponse, error) {
resp, err := c.UpgradeClusterOperationToDTO(op)
if err != nil {
return orchestration.OperationDetailResponse{}, errors.Wrap(err, "while converting operation to DTO")
}
return orchestration.OperationDetailResponse{
OperationResponse: resp,
ClusterConfig: clusterConfig,
}, nil
}