-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from tarantool/tarantool3-provider
Add static viper tarantool 3 configuration provider
- Loading branch information
Showing
14 changed files
with
321 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package moonlibs | ||
|
||
// ----- Moonlibs configuration ----- | ||
|
||
// Config is a representation of the topology configuration for tarantool version below 3. | ||
// based on https://github.com/moonlibs/config?tab=readme-ov-file#example-of-etcd-configuration-etcdclustermaster. | ||
type Config struct { | ||
Topology SourceTopologyConfig `json:"topology"` | ||
} | ||
|
||
type SourceTopologyConfig struct { | ||
Clusters map[string]ClusterInfo `json:"clusters,omitempty" yaml:"clusters" ` | ||
Instances map[string]InstanceInfo `json:"instances,omitempty" yaml:"instances"` | ||
} | ||
|
||
type ClusterInfo struct { | ||
ReplicasetUUID string `yaml:"replicaset_uuid" mapstructure:"replicaset_uuid"` | ||
} | ||
|
||
type InstanceInfo struct { | ||
Cluster string | ||
Box struct { | ||
Listen string `json:"listen,omitempty" yaml:"listen" mapstructure:"listen"` | ||
InstanceUUID string `yaml:"instance_uuid" mapstructure:"instance_uuid" json:"instanceUUID,omitempty"` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package moonlibs | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/google/uuid" | ||
vshardrouter "github.com/tarantool/go-vshard-router" | ||
) | ||
|
||
func (cfg *Config) Convert() map[vshardrouter.ReplicasetInfo][]vshardrouter.InstanceInfo { | ||
if cfg.Topology.Instances == nil { | ||
panic("instances is nil") | ||
} | ||
|
||
if cfg.Topology.Clusters == nil { | ||
panic("clusters is nil") | ||
} | ||
|
||
// prepare vshard router config | ||
vshardRouterTopology := make(map[vshardrouter.ReplicasetInfo][]vshardrouter.InstanceInfo) | ||
|
||
for rsName, rs := range cfg.Topology.Clusters { | ||
rsUUID, err := uuid.Parse(rs.ReplicasetUUID) | ||
if err != nil { | ||
panic("Can't parse replicaset uuid: %s") | ||
} | ||
|
||
rsInstances := make([]vshardrouter.InstanceInfo, 0) | ||
|
||
for _, instInfo := range cfg.Topology.Instances { | ||
if instInfo.Cluster != rsName { | ||
continue | ||
} | ||
|
||
instUUID, err := uuid.Parse(instInfo.Box.InstanceUUID) | ||
if err != nil { | ||
log.Printf("Can't parse replicaset uuid: %s", err) | ||
|
||
panic(err) | ||
} | ||
|
||
rsInstances = append(rsInstances, vshardrouter.InstanceInfo{ | ||
Addr: instInfo.Box.Listen, | ||
UUID: instUUID, | ||
}) | ||
} | ||
|
||
vshardRouterTopology[vshardrouter.ReplicasetInfo{ | ||
Name: rsName, | ||
UUID: rsUUID, | ||
}] = rsInstances | ||
} | ||
|
||
return vshardRouterTopology | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.