-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added viper tarantool 3 configuration provider
- Loading branch information
maksim.konovalov
committed
Dec 23, 2024
1 parent
249e9ba
commit adc0243
Showing
12 changed files
with
345 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package moonlibs | ||
|
||
// ----- Moonlibs configuration ----- | ||
|
||
// Config is a representation of the topology configuration for tarantool version below 3. | ||
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") | ||
} | ||
|
||
// готовим конфиг для vshard-router`а | ||
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
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,57 @@ | ||
package tarantool3 | ||
|
||
// ----- Tarantool 3 configuration ----- | ||
|
||
// Config - configuration for all groups | ||
type Config struct { | ||
Groups Group `yaml:"groups"` | ||
} | ||
|
||
// Group is a structure for each group configuration | ||
type Group struct { | ||
Storages *Storages `yaml:"storages,omitempty"` | ||
} | ||
|
||
// Storages configuration | ||
type Storages struct { | ||
App App `yaml:"app"` | ||
Sharding Sharding `yaml:"sharding"` | ||
Replication Replication `yaml:"replication"` | ||
Replicasets map[string]Replicaset `yaml:"replicasets"` | ||
} | ||
|
||
// App - general information about the module | ||
type App struct { | ||
Module string `yaml:"module"` | ||
} | ||
|
||
// Sharding configuration | ||
type Sharding struct { | ||
Roles []string `yaml:"roles"` | ||
} | ||
|
||
// Replication configuration | ||
type Replication struct { | ||
Failover string `yaml:"failover"` | ||
} | ||
|
||
// Replicaset configuration | ||
type Replicaset struct { | ||
Leader string `yaml:"leader"` | ||
Instances map[string]Instance `yaml:"instances"` | ||
} | ||
|
||
// Instance in the Replicaset | ||
type Instance struct { | ||
IProto IProto `yaml:"iproto"` | ||
} | ||
|
||
// IProto configuration | ||
type IProto struct { | ||
Listen []Listen `yaml:"listen"` | ||
} | ||
|
||
// Listen configuration (URI for connection) | ||
type Listen struct { | ||
URI string `yaml:"uri"` | ||
} |
Oops, something went wrong.