Skip to content

Commit

Permalink
placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
michalpristas committed Sep 8, 2020
1 parent 015f51f commit 54d9037
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ const (
// After running Upgrade agent should download its own version specified by action
// from repository specified by fleet.
type handlerUpgrade struct {
settings *artifact.Config
log *logger.Logger
emitter emitterFunc
dispatcher programsDispatcher
closers []context.CancelFunc
actionStore *actionStore
settings *artifact.Config
log *logger.Logger
closers []context.CancelFunc
}

func (h *handlerUpgrade) Handle(ctx context.Context, a action, acker fleetAcker) error {
Expand All @@ -38,20 +35,29 @@ func (h *handlerUpgrade) Handle(ctx context.Context, a action, acker fleetAcker)
return fmt.Errorf("invalid type, expected ActionUpgrade and received %T", a)
}

// download artifact
_, err := h.downloadArtifact(ctx, action)
archivePath, err := h.downloadArtifact(ctx, action)
if err != nil {
return err
}

// TODO: unpack correctly, skip root (symlink, config...) unpack data/*
// TODO: change symlink
// TODO: mark update happened so we can handle grace period
// TODO: reexec
return nil
newHash, err := h.untar(ctx, action, archivePath)
if err != nil {
return err
}

if err := h.changeSymlink(ctx, action, newHash); err != nil {
return err
}

if err := h.markUpgrade(ctx, action); err != nil {
return err
}

return h.reexec(ctx, action)
}

func (h *handlerUpgrade) downloadArtifact(ctx context.Context, action *fleetapi.ActionUpgrade) (string, error) {
// do not update source config
settings := *h.settings
if action.SourceURI != "" {
settings.SourceURI = action.SourceURI
Expand All @@ -78,3 +84,23 @@ func (h *handlerUpgrade) downloadArtifact(ctx context.Context, action *fleetapi.

return path, nil
}

// untar unpacks archive correctly, skips root (symlink, config...) unpacks data/*
func (h *handlerUpgrade) untar(ctx context.Context, action *fleetapi.ActionUpgrade, archivePath string) (string, error) {
return "", errors.New("not yet implemented")
}

// changeSymlink changes root symlink so it points to updated version
func (h *handlerUpgrade) changeSymlink(ctx context.Context, action *fleetapi.ActionUpgrade, newHash string) error {
return errors.New("not yet implemented")
}

// markUpgrade marks update happened so we can handle grace period
func (h *handlerUpgrade) markUpgrade(ctx context.Context, action *fleetapi.ActionUpgrade) error {
return errors.New("not yet implemented")
}

// reexec restarts agent so new version is run
func (h *handlerUpgrade) reexec(ctx context.Context, action *fleetapi.ActionUpgrade) error {
return errors.New("not yet implemented")
}
9 changes: 3 additions & 6 deletions x-pack/elastic-agent/pkg/agent/application/managed_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,9 @@ func newManaged(
actionDispatcher.MustRegister(
&fleetapi.ActionUpgrade{},
&handlerUpgrade{
settings: cfg.Settings.DownloadConfig,
log: log,
emitter: emit,
dispatcher: router,
closers: []context.CancelFunc{managedApplication.cancelCtxFn},
actionStore: actionStore,
settings: cfg.Settings.DownloadConfig,
log: log,
closers: []context.CancelFunc{managedApplication.cancelCtxFn},
},
)

Expand Down

0 comments on commit 54d9037

Please sign in to comment.