Skip to content

Commit

Permalink
Merge pull request #585 from cgalibern/dev
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
cgalibern authored Aug 23, 2024
2 parents e4283c4 + 34cb406 commit f5d77e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
5 changes: 5 additions & 0 deletions core/rawconfig/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func NodeVarDir() string {
return filepath.Join(Paths.Var, "node")
}

func CollectorSentDir() string {
return filepath.Join(Paths.Var, "node", "collector", "config_sent")
}

func NodeConfigFile() string {
return filepath.Join(Paths.Etc, "node.conf")
}
Expand All @@ -75,6 +79,7 @@ func ClusterConfigFile() string {
func CreateMandatoryDirectories() error {
mandatoryDirs := []string{
NodeVarDir(),
CollectorSentDir(),
DNSUDSDir(),
Paths.Certs,
Paths.Etc,
Expand Down
26 changes: 19 additions & 7 deletions daemon/collector/post_feed_object_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/opensvc/om3/core/cluster"
"github.com/opensvc/om3/core/instance"
"github.com/opensvc/om3/core/naming"
"github.com/opensvc/om3/core/rawconfig"
"github.com/opensvc/om3/daemon/daemonenv"
"github.com/opensvc/om3/daemon/daemonsubsystem"
"github.com/opensvc/om3/daemon/msgbus"
Expand Down Expand Up @@ -53,13 +54,16 @@ type (

// objectConfigSent describes object config sent to the collector db.
// It is used to prevent send already sent configs to the collector and
// is dumped to the filesystem config_sent_v3.json to populate sent cache
// after daemon restart.
// is dumped to the filesystem <var>/collector/config_sent/<fqdn>.json to
// populate sent cache after daemon restart.
objectConfigSent struct {
SentAt time.Time `json:"sent_at"`
Checksum string `json:"csum"`

path naming.Path

// cacheFile is the file path to store objectConfigSent struct
cacheFile string
}
)

Expand Down Expand Up @@ -266,22 +270,30 @@ func (t *T) doPostObjectConfig(checksum string, b []byte, p naming.Path) error {
}

func (o *objectConfigSent) filename() string {
if o == nil || o.path.IsZero() {
if o == nil {
return ""
}
return filepath.Join(o.path.VarDir(), "config_sent_v3.json")
if len(o.cacheFile) == 0 {
if o.path.IsZero() {
return ""
}
flat := fmt.Sprintf("%s.%s.%s.json", o.path.Namespace, o.path.Kind, o.path.Name)
o.cacheFile = filepath.FromSlash(filepath.Join(rawconfig.CollectorSentDir(), flat))
}
return o.cacheFile
}

func (o *objectConfigSent) write() error {
if o == nil || o.path.IsZero() {
return ErrZeroPath
}
f, err := os.Create(o.filename())
sentTrace := o.filename()
f, err := os.Create(sentTrace)
if err != nil {
if err1 := os.MkdirAll(filepath.Dir(o.filename()), 0755); err1 != nil {
if err1 := os.MkdirAll(filepath.Dir(sentTrace), 0755); err1 != nil {
return errors.Join(err, err1)
}
if f, err = os.Create(o.filename()); err != nil {
if f, err = os.Create(sentTrace); err != nil {
return err
}
}
Expand Down

0 comments on commit f5d77e6

Please sign in to comment.