• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uber / cadence / 0187fdd2-f4a4-4c9a-97b4-6604937bf7be

09 May 2023 12:23AM UTC coverage: 57.253% (-0.002%) from 57.255%
0187fdd2-f4a4-4c9a-97b4-6604937bf7be

Pull #5252

buildkite

David Porter
Merge branch 'master' into feature/zonal-partitioning
Pull Request #5252: Feature/zonal partitioning

1460 of 1460 new or added lines in 51 files covered. (100.0%)

86909 of 151799 relevant lines covered (57.25%)

2482.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.88
/common/persistence/domainManager.go
1
// Copyright (c) 2017 Uber Technologies, Inc.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
// of this software and associated documentation files (the "Software"), to deal
5
// in the Software without restriction, including without limitation the rights
6
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
// copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in
11
// all copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
// THE SOFTWARE.
20

21
package persistence
22

23
import (
24
        "context"
25
        "time"
26

27
        "github.com/uber/cadence/common"
28
        "github.com/uber/cadence/common/log"
29
        "github.com/uber/cadence/common/types"
30
)
31

32
type (
33

34
        // domainManagerImpl implements DomainManager based on DomainStore and PayloadSerializer
35
        domainManagerImpl struct {
36
                serializer  PayloadSerializer
37
                persistence DomainStore
38
                logger      log.Logger
39
        }
40
)
41

42
var _ DomainManager = (*domainManagerImpl)(nil)
43

44
// NewDomainManagerImpl returns new DomainManager
45
func NewDomainManagerImpl(persistence DomainStore, logger log.Logger) DomainManager {
51✔
46
        return &domainManagerImpl{
51✔
47
                serializer:  NewPayloadSerializer(),
51✔
48
                persistence: persistence,
51✔
49
                logger:      logger,
51✔
50
        }
51✔
51
}
51✔
52

53
func (m *domainManagerImpl) GetName() string {
×
54
        return m.persistence.GetName()
×
55
}
×
56

57
func (m *domainManagerImpl) CreateDomain(
58
        ctx context.Context,
59
        request *CreateDomainRequest,
60
) (*CreateDomainResponse, error) {
63✔
61
        dc, err := m.toInternalDomainConfig(request.Config)
63✔
62
        if err != nil {
63✔
63
                return nil, err
×
64
        }
×
65
        return m.persistence.CreateDomain(ctx, &InternalCreateDomainRequest{
63✔
66
                Info:              request.Info,
63✔
67
                Config:            &dc,
63✔
68
                ReplicationConfig: request.ReplicationConfig,
63✔
69
                IsGlobalDomain:    request.IsGlobalDomain,
63✔
70
                ConfigVersion:     request.ConfigVersion,
63✔
71
                FailoverVersion:   request.FailoverVersion,
63✔
72
                LastUpdatedTime:   time.Unix(0, request.LastUpdatedTime),
63✔
73
        })
63✔
74
}
75

76
func (m *domainManagerImpl) GetDomain(
77
        ctx context.Context,
78
        request *GetDomainRequest,
79
) (*GetDomainResponse, error) {
773✔
80
        internalResp, err := m.persistence.GetDomain(ctx, request)
773✔
81
        if err != nil {
1,417✔
82
                return nil, err
644✔
83
        }
644✔
84

85
        dc, err := m.fromInternalDomainConfig(internalResp.Config)
132✔
86
        if err != nil {
132✔
87
                return nil, err
×
88
        }
×
89

90
        resp := &GetDomainResponse{
132✔
91
                Info:                        internalResp.Info,
132✔
92
                Config:                      &dc,
132✔
93
                ReplicationConfig:           internalResp.ReplicationConfig,
132✔
94
                IsGlobalDomain:              internalResp.IsGlobalDomain,
132✔
95
                ConfigVersion:               internalResp.ConfigVersion,
132✔
96
                FailoverVersion:             internalResp.FailoverVersion,
132✔
97
                FailoverNotificationVersion: internalResp.FailoverNotificationVersion,
132✔
98
                PreviousFailoverVersion:     internalResp.PreviousFailoverVersion,
132✔
99
                LastUpdatedTime:             internalResp.LastUpdatedTime.UnixNano(),
132✔
100
                NotificationVersion:         internalResp.NotificationVersion,
132✔
101
        }
132✔
102
        if internalResp.FailoverEndTime != nil {
132✔
103
                resp.FailoverEndTime = common.Int64Ptr(internalResp.FailoverEndTime.UnixNano())
×
104
        }
×
105
        return resp, nil
132✔
106
}
107

108
func (m *domainManagerImpl) UpdateDomain(
109
        ctx context.Context,
110
        request *UpdateDomainRequest,
111
) error {
×
112
        dc, err := m.toInternalDomainConfig(request.Config)
×
113
        if err != nil {
×
114
                return err
×
115
        }
×
116
        internalReq := &InternalUpdateDomainRequest{
×
117
                Info:                        request.Info,
×
118
                Config:                      &dc,
×
119
                ReplicationConfig:           request.ReplicationConfig,
×
120
                ConfigVersion:               request.ConfigVersion,
×
121
                FailoverVersion:             request.FailoverVersion,
×
122
                FailoverNotificationVersion: request.FailoverNotificationVersion,
×
123
                PreviousFailoverVersion:     request.PreviousFailoverVersion,
×
124
                LastUpdatedTime:             time.Unix(0, request.LastUpdatedTime),
×
125
                NotificationVersion:         request.NotificationVersion,
×
126
        }
×
127
        if request.FailoverEndTime != nil {
×
128
                internalReq.FailoverEndTime = common.TimePtr(time.Unix(0, *request.FailoverEndTime))
×
129
        }
×
130
        return m.persistence.UpdateDomain(ctx, internalReq)
×
131
}
132

133
func (m *domainManagerImpl) DeleteDomain(
134
        ctx context.Context,
135
        request *DeleteDomainRequest,
136
) error {
×
137
        return m.persistence.DeleteDomain(ctx, request)
×
138
}
×
139

140
func (m *domainManagerImpl) DeleteDomainByName(
141
        ctx context.Context,
142
        request *DeleteDomainByNameRequest,
143
) error {
×
144
        return m.persistence.DeleteDomainByName(ctx, request)
×
145
}
×
146

147
func (m *domainManagerImpl) ListDomains(
148
        ctx context.Context,
149
        request *ListDomainsRequest,
150
) (*ListDomainsResponse, error) {
943✔
151
        resp, err := m.persistence.ListDomains(ctx, request)
943✔
152
        if err != nil {
943✔
153
                return nil, err
×
154
        }
×
155
        domains := make([]*GetDomainResponse, 0, len(resp.Domains))
943✔
156
        for _, d := range resp.Domains {
5,478✔
157
                dc, err := m.fromInternalDomainConfig(d.Config)
4,535✔
158
                if err != nil {
4,535✔
159
                        return nil, err
×
160
                }
×
161
                currResp := &GetDomainResponse{
4,535✔
162
                        Info:                        d.Info,
4,535✔
163
                        Config:                      &dc,
4,535✔
164
                        ReplicationConfig:           d.ReplicationConfig,
4,535✔
165
                        IsGlobalDomain:              d.IsGlobalDomain,
4,535✔
166
                        ConfigVersion:               d.ConfigVersion,
4,535✔
167
                        FailoverVersion:             d.FailoverVersion,
4,535✔
168
                        FailoverNotificationVersion: d.FailoverNotificationVersion,
4,535✔
169
                        PreviousFailoverVersion:     d.PreviousFailoverVersion,
4,535✔
170
                        NotificationVersion:         d.NotificationVersion,
4,535✔
171
                }
4,535✔
172
                if d.FailoverEndTime != nil {
4,535✔
173
                        currResp.FailoverEndTime = common.Int64Ptr(d.FailoverEndTime.UnixNano())
×
174
                }
×
175
                domains = append(domains, currResp)
4,535✔
176
        }
177
        return &ListDomainsResponse{
943✔
178
                Domains:       domains,
943✔
179
                NextPageToken: resp.NextPageToken,
943✔
180
        }, nil
943✔
181
}
182

183
func (m *domainManagerImpl) toInternalDomainConfig(c *DomainConfig) (InternalDomainConfig, error) {
63✔
184
        if c == nil {
63✔
185
                return InternalDomainConfig{}, nil
×
186
        }
×
187
        if c.BadBinaries.Binaries == nil {
78✔
188
                c.BadBinaries.Binaries = map[string]*types.BadBinaryInfo{}
15✔
189
        }
15✔
190
        badBinaries, err := m.serializer.SerializeBadBinaries(&c.BadBinaries, common.EncodingTypeThriftRW)
63✔
191
        if err != nil {
63✔
192
                return InternalDomainConfig{}, err
×
193
        }
×
194
        isolationGroups, err := m.serializer.SerializeIsolationGroups(&c.IsolationGroups, common.EncodingTypeThriftRW)
63✔
195
        if err != nil {
63✔
196
                return InternalDomainConfig{}, err
×
197
        }
×
198
        return InternalDomainConfig{
63✔
199
                Retention:                common.DaysToDuration(c.Retention),
63✔
200
                EmitMetric:               c.EmitMetric,
63✔
201
                HistoryArchivalStatus:    c.HistoryArchivalStatus,
63✔
202
                HistoryArchivalURI:       c.HistoryArchivalURI,
63✔
203
                VisibilityArchivalStatus: c.VisibilityArchivalStatus,
63✔
204
                VisibilityArchivalURI:    c.VisibilityArchivalURI,
63✔
205
                BadBinaries:              badBinaries,
63✔
206
                IsolationGroups:          isolationGroups,
63✔
207
        }, nil
63✔
208
}
209

210
func (m *domainManagerImpl) fromInternalDomainConfig(ic *InternalDomainConfig) (DomainConfig, error) {
4,664✔
211
        if ic == nil {
4,664✔
212
                return DomainConfig{}, nil
×
213
        }
×
214
        badBinaries, err := m.serializer.DeserializeBadBinaries(ic.BadBinaries)
4,664✔
215
        if err != nil {
4,664✔
216
                return DomainConfig{}, err
×
217
        }
×
218
        var isolationGroups types.IsolationGroupConfiguration
4,664✔
219
        igRes, err := m.serializer.DeserializeIsolationGroups(ic.IsolationGroups)
4,664✔
220
        if err != nil {
4,664✔
221
                return DomainConfig{}, err
×
222
        }
×
223
        if igRes != nil {
9,009✔
224
                isolationGroups = *igRes
4,345✔
225
        }
4,345✔
226

227
        if badBinaries.Binaries == nil {
4,984✔
228
                badBinaries.Binaries = map[string]*types.BadBinaryInfo{}
320✔
229
        }
320✔
230
        return DomainConfig{
4,664✔
231
                Retention:                common.DurationToDays(ic.Retention),
4,664✔
232
                EmitMetric:               ic.EmitMetric,
4,664✔
233
                HistoryArchivalStatus:    ic.HistoryArchivalStatus,
4,664✔
234
                HistoryArchivalURI:       ic.HistoryArchivalURI,
4,664✔
235
                VisibilityArchivalStatus: ic.VisibilityArchivalStatus,
4,664✔
236
                VisibilityArchivalURI:    ic.VisibilityArchivalURI,
4,664✔
237
                BadBinaries:              *badBinaries,
4,664✔
238
                IsolationGroups:          isolationGroups,
4,664✔
239
        }, nil
4,664✔
240
}
241

242
func (m *domainManagerImpl) GetMetadata(
243
        ctx context.Context,
244
) (*GetMetadataResponse, error) {
943✔
245
        return m.persistence.GetMetadata(ctx)
943✔
246
}
943✔
247

248
func (m *domainManagerImpl) Close() {
39✔
249
        m.persistence.Close()
39✔
250
}
39✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc