Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,6 @@ Where the password is the value of the `þassword` key in `system/sec/relay-v3`.

* Flush iptables rules created by om2. om3 now configures the firewall using nft only.

* Change `ips_per_node` to `mask_per_node`. The former was inadequate for large subnets (ipv6). For example, `ips_per_node=18446744073709551616` is easier expressed as `mask_per_node=64`. Backward compatibility is maintained for this release.


78 changes: 33 additions & 45 deletions core/driver/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ const (
GroupApp
GroupSync
GroupTask
GroupCertificate
GroupExpose
GroupRoute
GroupVhost
GroupPool
GroupNetwork
GroupHeartbeat
Expand All @@ -33,51 +29,43 @@ const (
)

var (
resourceGroups = GroupIP | GroupVolume | GroupDisk | GroupFS | GroupShare | GroupContainer | GroupApp | GroupSync | GroupTask | GroupCertificate | GroupExpose | GroupRoute | GroupVhost
resourceGroups = GroupIP | GroupVolume | GroupDisk | GroupFS | GroupShare | GroupContainer | GroupApp | GroupSync | GroupTask

toGroupID = map[string]Group{
"ip": GroupIP,
"volume": GroupVolume,
"disk": GroupDisk,
"fs": GroupFS,
"share": GroupShare,
"container": GroupContainer,
"app": GroupApp,
"sync": GroupSync,
"task": GroupTask,
"certificate": GroupCertificate,
"expose": GroupExpose,
"route": GroupRoute,
"vhost": GroupVhost,
"pool": GroupPool,
"network": GroupNetwork,
"hb": GroupHeartbeat,
"array": GroupArray,
"switch": GroupSwitch,
"stonith": GroupStonith,
"backup": GroupBackup,
"ip": GroupIP,
"volume": GroupVolume,
"disk": GroupDisk,
"fs": GroupFS,
"share": GroupShare,
"container": GroupContainer,
"app": GroupApp,
"sync": GroupSync,
"task": GroupTask,
"pool": GroupPool,
"network": GroupNetwork,
"hb": GroupHeartbeat,
"array": GroupArray,
"switch": GroupSwitch,
"stonith": GroupStonith,
"backup": GroupBackup,
}
toGroupString = map[Group]string{
GroupIP: "ip",
GroupVolume: "volume",
GroupDisk: "disk",
GroupFS: "fs",
GroupShare: "share",
GroupContainer: "container",
GroupApp: "app",
GroupSync: "sync",
GroupTask: "task",
GroupCertificate: "certificate",
GroupExpose: "expose",
GroupRoute: "route",
GroupVhost: "vhost",
GroupPool: "pool",
GroupNetwork: "network",
GroupHeartbeat: "hb",
GroupArray: "array",
GroupSwitch: "switch",
GroupStonith: "stonith",
GroupBackup: "backup",
GroupIP: "ip",
GroupVolume: "volume",
GroupDisk: "disk",
GroupFS: "fs",
GroupShare: "share",
GroupContainer: "container",
GroupApp: "app",
GroupSync: "sync",
GroupTask: "task",
GroupPool: "pool",
GroupNetwork: "network",
GroupHeartbeat: "hb",
GroupArray: "array",
GroupSwitch: "switch",
GroupStonith: "stonith",
GroupBackup: "backup",
}
)

Expand Down
16 changes: 9 additions & 7 deletions core/instance/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ type (
IsDisabled bool `json:"is_disabled"`
IsMonitored bool `json:"is_monitored"`
IsStandby bool `json:"is_standby"`
Restart int `json:"restart"`
RestartDelay *time.Duration `json:"restart_delay"`
Restart int `json:"restart,omitempty"`
RestartDelay *time.Duration `json:"restart_delay,omitempty"`
}
SubsetConfig struct {
Parallel bool `json:"parallel,omitempty"`
Expand Down Expand Up @@ -172,11 +172,13 @@ func (t Config) Unstructured() map[string]any {

func (t ResourceConfig) Unstructured() map[string]any {
m := map[string]any{
"is_disabled": t.IsDisabled,
"is_monitored": t.IsMonitored,
"is_standby": t.IsStandby,
"restart": t.Restart,
"restart_delay": t.RestartDelay,
"is_disabled": t.IsDisabled,
"is_monitored": t.IsMonitored,
"is_standby": t.IsStandby,
"restart": t.Restart,
}
if t.RestartDelay != nil {
m["restart_delay"] = t.RestartDelay
}
return m
}
Expand Down
1 change: 0 additions & 1 deletion core/instance/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func Test_Status_Unmarshal(t *testing.T) {
Mtime: time.Date(2022, time.November, 28, 21, 46, 25, 849702075, time.UTC),
State: provisioned.False,
},
Restart: 2,
},
},
}
Expand Down
57 changes: 37 additions & 20 deletions core/instance/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/google/uuid"

"github.com/opensvc/om3/v3/core/status"
"github.com/opensvc/om3/v3/util/xmap"
)

type (
Expand Down Expand Up @@ -72,11 +71,11 @@ type (
// ResourceMonitor describes the restart states maintained by the daemon
// for an object instance.
ResourceMonitor struct {
Restart ResourceMonitorRestart `json:"restart"`
Restart *ResourceMonitorRestart `json:"restart,omitempty"`
}
ResourceMonitorRestart struct {
Remaining int `json:"remaining"`
LastAt time.Time `json:"last_at"`
Remaining int `json:"remaining,omitempty"`
LastAt time.Time `json:"last_at,omitempty"`
}

MonitorState int
Expand Down Expand Up @@ -200,12 +199,20 @@ func (t *MonitorGlobalExpect) UnmarshalText(b []byte) error {
}
}

func (rmon *ResourceMonitor) DecRestartRemaining() {
if rmon.Restart.Remaining > 0 {
rmon.Restart.Remaining -= 1
func (m *ResourceMonitor) DecRestartRemaining() {
if m.Restart.Remaining > 0 {
m.Restart.Remaining -= 1
}
}

func (t *ResourceMonitor) Unstructured() map[string]any {
m := map[string]any{}
if t.Restart != nil {
m["restart"] = t.Restart.Unstructured()
}
return m
}

func (m ResourceMonitors) Set(rid string, rmon ResourceMonitor) {
m[rid] = rmon
}
Expand All @@ -219,7 +226,21 @@ func (m ResourceMonitors) Get(rid string) *ResourceMonitor {
}

func (m ResourceMonitors) DeepCopy() ResourceMonitors {
return xmap.Copy(m)
c := make(ResourceMonitors)
for k, v := range m {
c[k] = ResourceMonitor{
Restart: v.Restart.DeepCopy(),
}
}
return c
}

func (t ResourceMonitors) Unstructured() map[string]map[string]any {
m := make(map[string]map[string]any)
for k, v := range t {
m[k] = v.Unstructured()
}
return m
}

func (mon Monitor) DeepCopy() *Monitor {
Expand All @@ -243,13 +264,17 @@ func (mon Monitor) DeepCopy() *Monitor {
return &v
}

func (t ResourceMonitor) Unstructured() map[string]any {
return map[string]any{
"restart": t.Restart.Unstructured(),
func (t *ResourceMonitorRestart) DeepCopy() *ResourceMonitorRestart {
if t == nil {
return nil
}
return &ResourceMonitorRestart{
Remaining: t.Remaining,
LastAt: t.LastAt,
}
}

func (t ResourceMonitorRestart) Unstructured() map[string]any {
func (t *ResourceMonitorRestart) Unstructured() map[string]any {
return map[string]any{
"remaining": t.Remaining,
"last_at": t.LastAt,
Expand Down Expand Up @@ -286,14 +311,6 @@ func (t Monitor) Unstructured() map[string]any {
return m
}

func (t ResourceMonitors) Unstructured() map[string]map[string]any {
m := make(map[string]map[string]any)
for k, v := range t {
m[k] = v.Unstructured()
}
return m
}

func (t MonitorUpdate) String() string {
s := fmt.Sprintf("CandidateOrchestrationID=%s", t.CandidateOrchestrationID)
if t.State != nil {
Expand Down
6 changes: 3 additions & 3 deletions core/instance/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Test_Monitor_Unmarshal(t *testing.T) {
StateUpdatedAt: t0,
Resources: ResourceMonitors{
"fs#1": ResourceMonitor{
Restart: ResourceMonitorRestart{
Restart: &ResourceMonitorRestart{
Remaining: 1,
LastAt: time.Date(2020, time.March, 4, 16, 33, 23, 167003830, time.UTC),
},
Expand All @@ -62,8 +62,8 @@ func Test_Monitor_DeepCopy(t *testing.T) {
LocalExpectUpdatedAt: time.Now(),
GlobalExpectUpdatedAt: time.Now(),
Resources: ResourceMonitors{
"a": ResourceMonitor{Restart: ResourceMonitorRestart{Remaining: 1, LastAt: time.Now()}},
"b": ResourceMonitor{Restart: ResourceMonitorRestart{Remaining: 8, LastAt: time.Now()}},
"a": ResourceMonitor{Restart: &ResourceMonitorRestart{Remaining: 1, LastAt: time.Now()}},
"b": ResourceMonitor{Restart: &ResourceMonitorRestart{Remaining: 8, LastAt: time.Now()}},
},
}
mon2 := *mon1.DeepCopy()
Expand Down
10 changes: 6 additions & 4 deletions core/instance/states_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,19 @@ func (t States) LoadTreeNode(head *tree.Node) {
subsetNode.AddColumn()
subsetNode.AddColumn()
parallel := ""
if subset, ok := t.Config.Subsets[resourceSetName]; ok {
if subset.Parallel {
parallel = "//"
if t.Config.ActorConfig != nil {
if subset, ok := t.Config.Subsets[resourceSetName]; ok {
if subset.Parallel {
parallel = "//"
}
}
}
subsetNode.AddColumn().AddText(parallel)
}
lastSubset = r.Subset
}
doResource := func(n *tree.Node, r resource.Status) *tree.Column {
flags := ResourceFlagsString(r.ResourceID.Name, t.Monitor, t.Status, r)
flags := ResourceFlagsString(r.ResourceID.Name, t, r)
n.AddColumn().AddText(r.ResourceID.Name)
n.AddColumn().AddText(flags)
n.AddColumn().AddText(colorstatus.Sprint(r.Status, rawconfig.Colorize))
Expand Down
22 changes: 16 additions & 6 deletions core/instance/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,34 @@ func (a ResourceOrder) Less(i, j int) bool {
// P Provisioned
// S Standby
// <n> Restart remaining, + More than 9 remaining, X UserStopped
func ResourceFlagsString(rid string, mon Monitor, status Status, rstatus resource.Status) string {
func ResourceFlagsString(rid string, states States, rstatus resource.Status) string {
runningFlag := func() string {
if status.Running.Has(rid) {
if states.Status.Running.Has(rid) {
return "R"
} else {
return "."
}
}
restartFlag := func() string {
if states.Config.ActorConfig == nil {
// only actors have the Resources field
return "."
}
retries := 0
if rmon := mon.Resources.Get(rid); rmon != nil {
retries = rmon.Restart.Remaining
restart := 0
if rcfg := states.Config.Resources.Get(rid); rcfg != nil {
restart = rcfg.Restart
}
if rmon := states.Monitor.Resources.Get(rid); rmon != nil {
if rmon.Restart != nil {
retries = rmon.Restart.Remaining
}
}
s := rstatus.RestartFlag(retries)
s := rstatus.RestartFlag(restart, retries)
if s == "." {
return s
}
if mon.LocalExpect != MonitorLocalExpectStarted || status.IsFrozen() {
if states.Monitor.LocalExpect != MonitorLocalExpectStarted || states.Status.IsFrozen() {
s = rawconfig.Colorize.Secondary(s)
}
return s
Expand Down
4 changes: 2 additions & 2 deletions core/manifest/dbkeywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ var (
}

KWRestart = keywords.Keyword{
Attr: "Restart",
Attr: "Restart.Count",
Default: "0",
Converter: "int",
Option: "restart",
Expand All @@ -215,7 +215,7 @@ var (
}

KWRestartDelay = keywords.Keyword{
Attr: "RestartDelay",
Attr: "Restart.Delay",
Converter: "duration",
Default: "500ms",
Option: "restart_delay",
Expand Down
Loading