From 54d903755daaa7204941e6314e36978653f82086 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 8 Sep 2020 10:02:55 +0200 Subject: [PATCH] placeholders --- .../application/handler_action_upgrade.go | 52 ++++++++++++++----- .../pkg/agent/application/managed_mode.go | 9 ++-- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/x-pack/elastic-agent/pkg/agent/application/handler_action_upgrade.go b/x-pack/elastic-agent/pkg/agent/application/handler_action_upgrade.go index 67942566f0e3..4979f1ad6638 100644 --- a/x-pack/elastic-agent/pkg/agent/application/handler_action_upgrade.go +++ b/x-pack/elastic-agent/pkg/agent/application/handler_action_upgrade.go @@ -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 { @@ -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 @@ -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") +} diff --git a/x-pack/elastic-agent/pkg/agent/application/managed_mode.go b/x-pack/elastic-agent/pkg/agent/application/managed_mode.go index 2b49feddb3ad..2cd8ac2c76c1 100644 --- a/x-pack/elastic-agent/pkg/agent/application/managed_mode.go +++ b/x-pack/elastic-agent/pkg/agent/application/managed_mode.go @@ -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}, }, )