|
| 1 | +// The MIT License (MIT) |
| 2 | + |
| 3 | +// Copyright (c) 2017-2020 Uber Technologies Inc. |
| 4 | + |
| 5 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +// of this software and associated documentation files (the "Software"), to deal |
| 7 | +// in the Software without restriction, including without limitation the rights |
| 8 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +// copies of the Software, and to permit persons to whom the Software is |
| 10 | +// furnished to do so, subject to the following conditions: |
| 11 | +// |
| 12 | +// The above copyright notice and this permission notice shall be included in all |
| 13 | +// copies or substantial portions of the Software. |
| 14 | +// |
| 15 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +// SOFTWARE. |
| 22 | + |
| 23 | +package activecluster |
| 24 | + |
| 25 | +import ( |
| 26 | + "context" |
| 27 | + |
| 28 | + "github.com/uber/cadence/common" |
| 29 | + "github.com/uber/cadence/common/cache" |
| 30 | + "github.com/uber/cadence/common/cluster" |
| 31 | + "github.com/uber/cadence/common/log" |
| 32 | + "github.com/uber/cadence/common/log/tag" |
| 33 | + "github.com/uber/cadence/common/metrics" |
| 34 | +) |
| 35 | + |
| 36 | +//go:generate mockgen -package $GOPACKAGE -destination manager_mock.go -self_package github.com/uber/cadence/common/activecluster github.com/uber/cadence/common/activecluster Manager |
| 37 | + |
| 38 | +type Manager interface { |
| 39 | + common.Daemon |
| 40 | + |
| 41 | + ActiveCluster(ctx context.Context, domainID, wfID, rID string) (string, error) |
| 42 | + FailoverVersion(ctx context.Context, domainID, wfID, rID string) (int64, error) |
| 43 | +} |
| 44 | + |
| 45 | +type DomainIDToDomainFn func(id string) (*cache.DomainCacheEntry, error) |
| 46 | + |
| 47 | +type manager struct { |
| 48 | + domainIDToDomainFn DomainIDToDomainFn |
| 49 | + clusterMetadata cluster.Metadata |
| 50 | + metricsCl metrics.Client |
| 51 | + logger log.Logger |
| 52 | +} |
| 53 | + |
| 54 | +func NewManager( |
| 55 | + domainIDToDomainFn DomainIDToDomainFn, |
| 56 | + clusterMetadata cluster.Metadata, |
| 57 | + metricsCl metrics.Client, |
| 58 | + logger log.Logger, |
| 59 | +) Manager { |
| 60 | + return &manager{ |
| 61 | + domainIDToDomainFn: domainIDToDomainFn, |
| 62 | + clusterMetadata: clusterMetadata, |
| 63 | + metricsCl: metricsCl, |
| 64 | + logger: logger.WithTags(tag.ComponentActiveRegionManager), |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +func (m *manager) ActiveCluster(ctx context.Context, domainID, wfID, rID string) (string, error) { |
| 69 | + d, err := m.domainIDToDomainFn(domainID) |
| 70 | + if err != nil { |
| 71 | + return "", err |
| 72 | + } |
| 73 | + |
| 74 | + if !d.GetReplicationConfig().IsActiveActive() { |
| 75 | + // Not an active-active domain. return ActiveClusterName from domain entry |
| 76 | + return d.GetReplicationConfig().ActiveClusterName, nil |
| 77 | + } |
| 78 | + |
| 79 | + // TODO: Remove below fake implementation and implement properly |
| 80 | + // - lookup active region given <domain id, wf id, run id> from executions table RowType=ActiveCluster. |
| 81 | + // - cache this info |
| 82 | + // - add metrics for cache hit/miss |
| 83 | + // - return cluster name |
| 84 | + if wfID == "wf1" { |
| 85 | + return "cluster0", nil |
| 86 | + } |
| 87 | + if wfID == "wf2" { |
| 88 | + return "cluster1", nil |
| 89 | + } |
| 90 | + |
| 91 | + return d.GetReplicationConfig().ActiveClusterName, nil |
| 92 | +} |
| 93 | + |
| 94 | +func (m *manager) FailoverVersion(ctx context.Context, domainID, wfID, rID string) (int64, error) { |
| 95 | + // TODO: implement this |
| 96 | + return 0, nil |
| 97 | +} |
| 98 | + |
| 99 | +func (m *manager) Start() { |
| 100 | +} |
| 101 | + |
| 102 | +func (m *manager) Stop() { |
| 103 | +} |
0 commit comments