Skip to content
Merged
9 changes: 9 additions & 0 deletions core/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var (
NamespaceVar = "OSVC_NAMESPACE"
KindVar = "OSVC_KIND"
ContextVar = "OSVC_CONTEXT"

NoLogFileVar = "OSVC_NO_LOG_FILE"
)

// HasDaemonOrigin returns true if the environment variable OSVC_ACTION_ORIGIN
Expand Down Expand Up @@ -91,3 +93,10 @@ func Kind() string {
func Context() string {
return os.Getenv(ContextVar)
}

func NoLogFile() bool {
return os.Getenv(NoLogFileVar) == "1"
}
func NoLogFileSetenvArg() string {
return fmt.Sprintf("%s=1", NoLogFileVar)
}
10 changes: 7 additions & 3 deletions core/naming/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,17 @@ func (t Paths) Merge(other Paths) Paths {
// variable persistent data is stored as files.
func (t Path) VarDir() string {
var s string
if t.IsZero() {
return filepath.Join(rawconfig.Paths.Var, "node")
}

switch t.Namespace {
case "", NsRoot:
s = fmt.Sprintf("%s/%s/%s", rawconfig.Paths.Var, t.Kind, t.Name)
s = filepath.Join(rawconfig.Paths.Var, t.Kind.String(), t.Name)
default:
s = fmt.Sprintf("%s/%s", rawconfig.Paths.VarNs, t)
s = filepath.Join(rawconfig.Paths.VarNs, t.String())
}
return filepath.FromSlash(s)
return s
}

// TmpDir returns the directory on the local filesystem where the object
Expand Down
64 changes: 49 additions & 15 deletions core/node/config.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,59 @@
package node

import "time"
import (
"time"

"github.com/opensvc/om3/v3/core/schedule"
)

type (
Config struct {
Env string `json:"env"`
MaintenanceGracePeriod time.Duration `json:"maintenance_grace_period"`
MaxParallel int `json:"max_parallel"`
MaxKeySize int64 `json:"max_key_size"`
MinAvailMemPct int `json:"min_avail_mem_pct"`
MinAvailSwapPct int `json:"min_avail_swap_pct"`
ReadyPeriod time.Duration `json:"ready_period"`
RejoinGracePeriod time.Duration `json:"rejoin_grace_period"`
SplitAction string `json:"split_action"`
SSHKey string `json:"sshkey"`
PRKey string `json:"prkey"`
Env string `json:"env"`
MaintenanceGracePeriod time.Duration `json:"maintenance_grace_period"`
MaxParallel int `json:"max_parallel"`
MaxKeySize int64 `json:"max_key_size"`
MinAvailMemPct int `json:"min_avail_mem_pct"`
MinAvailSwapPct int `json:"min_avail_swap_pct"`
ReadyPeriod time.Duration `json:"ready_period"`
RejoinGracePeriod time.Duration `json:"rejoin_grace_period"`
Schedules []schedule.Config `json:"schedules"`
SplitAction string `json:"split_action"`
SSHKey string `json:"sshkey"`
PRKey string `json:"prkey"`
}
)

func (t *Config) DeepCopy() *Config {
var data Config = *t
return &data
func (cfg *Config) DeepCopy() *Config {
newCfg := *cfg
newCfg.Schedules = append([]schedule.Config{}, cfg.Schedules...)
return &newCfg

}

func (c Config) Equals(other Config) bool {
if c.Env != other.Env ||
c.MaintenanceGracePeriod != other.MaintenanceGracePeriod ||
c.MaxParallel != other.MaxParallel ||
c.MaxKeySize != other.MaxKeySize ||
c.MinAvailMemPct != other.MinAvailMemPct ||
c.MinAvailSwapPct != other.MinAvailSwapPct ||
c.ReadyPeriod != other.ReadyPeriod ||
c.RejoinGracePeriod != other.RejoinGracePeriod ||
c.SplitAction != other.SplitAction ||
c.SSHKey != other.SSHKey ||
c.PRKey != other.PRKey {
return false
}

// Compare Schedules slice
if len(c.Schedules) != len(other.Schedules) {
return false
}
for i := range c.Schedules {
if c.Schedules[i] != other.Schedules[i] {
return false
}
}

return true
}
27 changes: 7 additions & 20 deletions core/object/actor_print_schedule.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package object

import (
"path/filepath"
"time"

"github.com/opensvc/om3/v3/core/kwoption"
"github.com/opensvc/om3/v3/core/naming"
"github.com/opensvc/om3/v3/core/resource"
"github.com/opensvc/om3/v3/core/schedule"
"github.com/opensvc/om3/v3/util/file"
"github.com/opensvc/om3/v3/util/hostname"
"github.com/opensvc/om3/v3/util/key"
)
Expand All @@ -21,16 +17,7 @@ func (t *actor) lastRunFile(action, rid, desc string) string {
if rid != "" {
base = base + "_" + rid
}
return filepath.Join(t.VarDir(), "scheduler", base)
}

func (t *actor) lastSuccessFile(action, rid, base string) string {
return filepath.Join(t.lastRunFile(action, rid, base) + ".success")
}

func (t *actor) loadLast(action, rid, base string) time.Time {
fpath := t.lastRunFile(action, rid, base)
return file.ModTime(fpath)
return base
}

func (t *actor) newScheduleEntry(action, keyStr, rid, base string, reqCol, reqProv bool) schedule.Entry {
Expand All @@ -39,21 +26,21 @@ func (t *actor) newScheduleEntry(action, keyStr, rid, base string, reqCol, reqPr
if err != nil {
panic(err)
}
return schedule.Entry{
entry := schedule.Entry{
Config: schedule.Config{
Action: action,
Key: k.String(),
LastRunFile: t.lastRunFile(action, rid, base),
LastSuccessFile: t.lastSuccessFile(action, rid, base),
MaxParallel: 1,
RequireCollector: reqCol,
RequireProvisioned: reqProv,
Schedule: def,
StatefileKey: t.lastRunFile(action, rid, base),
},
LastRunAt: t.loadLast(action, rid, base),
Node: hostname.Hostname(),
Path: t.path,
Node: hostname.Hostname(),
Path: t.path,
}
entry.LastRunAt = entry.LoadLast()
return entry
}

func (t *actor) Schedules() schedule.Table {
Expand Down
28 changes: 6 additions & 22 deletions core/object/node_print_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ package object

import (
"fmt"
"path/filepath"
"time"

"github.com/opensvc/om3/v3/core/driver"
"github.com/opensvc/om3/v3/core/resource"
"github.com/opensvc/om3/v3/core/resourceid"
"github.com/opensvc/om3/v3/core/schedule"
"github.com/opensvc/om3/v3/util/file"
"github.com/opensvc/om3/v3/util/hostname"
"github.com/opensvc/om3/v3/util/key"
)
Expand All @@ -19,16 +15,7 @@ func (t *Node) lastRunFile(action, rid, base string) string {
if rid != "" {
base = base + "_" + rid
}
return filepath.Join(t.VarDir(), "scheduler", base)
}

func (t *Node) lastSuccessFile(action, rid, base string) string {
return filepath.Join(t.lastRunFile(action, rid, base) + ".success")
}

func (t *Node) loadLast(action, rid, base string) time.Time {
fpath := t.lastRunFile(action, rid, base)
return file.ModTime(fpath)
return base
}

func (t *Node) newScheduleEntry(action, section, rid, base string) schedule.Entry {
Expand All @@ -37,19 +24,19 @@ func (t *Node) newScheduleEntry(action, section, rid, base string) schedule.Entr
if err != nil {
panic(err)
}
return schedule.Entry{
entry := schedule.Entry{
Config: schedule.Config{
Action: action,
Key: k.String(),
LastRunFile: t.lastRunFile(action, rid, base),
LastSuccessFile: t.lastSuccessFile(action, rid, base),
MaxParallel: 1,
RequireCollector: true,
Schedule: def,
StatefileKey: t.lastRunFile(action, rid, base),
},
LastRunAt: t.loadLast(action, rid, base),
Node: hostname.Hostname(),
Node: hostname.Hostname(),
}
entry.LastRunAt = entry.LoadLast()
return entry
}

func (t *Node) Schedules() schedule.Table {
Expand All @@ -63,9 +50,6 @@ func (t *Node) Schedules() schedule.Table {
t.newScheduleEntry("sysreport", "sysreport", "", "sysreport_push"),
t.newScheduleEntry("dequeue_actions", "dequeue_actions", "", "dequeue_actions_push"),
)
type scheduleOptioner interface {
ScheduleOptions() resource.ScheduleOptions
}
for _, s := range t.config.SectionStrings() {
rid, err := resourceid.Parse(s)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions core/om/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ func configureLogger() error {
if traceFlag {
level = "trace"
}
noLogFile := env.NoLogFile()
err := logging.Configure(logging.Config{
WithConsoleLog: !quietFlag || debugFlag || traceFlag || foregroundFlag,
WithColor: colorFlag != "no",
WithCaller: callerFlag,
WithJournald: !noLogFile,
WithSyslogd: !noLogFile,
Level: level,
})
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions core/omcmd/node_schedule_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ func (t *CmdNodeScheduleList) extractLocal() (api.ScheduleItems, error) {
Action: e.Action,
Key: e.Key,
LastRunAt: e.LastRunAt,
LastRunFile: e.LastRunFile,
LastSuccessFile: e.LastSuccessFile,
MaxParallel: e.MaxParallel,
NextRunAt: e.NextRunAt,
RequireCollector: e.RequireCollector,
RequireProvisioned: e.RequireProvisioned,
Schedule: e.Schedule,
StatefileKey: e.StatefileKey,
},
}
items = append(items, item)
Expand Down
3 changes: 1 addition & 2 deletions core/omcmd/object_schedule_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ func (t *CmdObjectScheduleList) extractLocal(selector string) (api.ScheduleList,
Action: e.Action,
Key: e.Key,
LastRunAt: e.LastRunAt,
LastRunFile: e.LastRunFile,
LastSuccessFile: e.LastSuccessFile,
MaxParallel: e.MaxParallel,
NextRunAt: e.NextRunAt,
Require: e.Require,
RequireCollector: e.RequireCollector,
RequireProvisioned: e.RequireProvisioned,
Schedule: e.Schedule,
StatefileKey: e.StatefileKey,
},
}
data.Items = append(data.Items, item)
Expand Down
4 changes: 1 addition & 3 deletions core/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,7 @@ func (t *T) GetObjectDriver() ObjectDriver {
}

func (t *T) getLoggerFromObjectDriver(o ObjectDriver) *plog.Logger {
oLog := o.Log()
prefix := fmt.Sprintf("%s%s: ", oLog.Prefix(), t.ResourceID)
l := plog.NewLogger(oLog.Logger()).WithPrefix(prefix).Attr("rid", t.ResourceID)
l := o.Log().AddPrefix(t.ResourceID.String()+": ").Attr("rid", t.ResourceID)
if t.Subset != "" {
l = l.Attr("subset", t.Subset)
}
Expand Down
Loading