client

package
v0.0.0-...-3bfe646 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Copyright 2018 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2019 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2019 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2018 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2019 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutomaticLifecycle

type AutomaticLifecycle struct {
	// Aborter specifies the completion handler for when the operation is aborted
	Aborter func(context.Context) error
	// Completer specifies the completion handler for when the operation
	// is completed successfully
	Completer CompletionHandler
	// DebugReportPath specifies the path to the debug report file
	DebugReportPath string
	// LocalDebugReporter specifies the handler for generating host-local debug
	// report
	LocalDebugReporter func(ctx context.Context, path string) error
}

AutomaticLifecycle handles the completion of an operation. If the operation is interrupted, it runs the abort handler. If the operation completes successfully, it runs the completion handler. If the operation fails, it generates a debug report

func (*AutomaticLifecycle) Abort

func (r *AutomaticLifecycle) Abort(ctx context.Context, c *Client) error

Abort invokes the abort handler after the operation has been interrupted

func (*AutomaticLifecycle) Complete

Complete shuts down the installer and invokes the completion handler

func (*AutomaticLifecycle) HandleStatus

func (r *AutomaticLifecycle) HandleStatus(ctx context.Context, c *Client, status pb.ProgressResponse_Status, statusErr error) error

HandleStatus handles the results of a completed operation. It executes the handler corresponding to the outcome

type Client

type Client struct {
	Config
	// contains filtered or unexported fields
}

Client implements the client to the installer service

func New

func New(ctx context.Context, config Config) (*Client, error)

New returns a new client for the installer/agent service. The client installs the service and starts the operation. If restarted, the client will either attempt to connect to a running installer service or set up a new one (subject to connection strategy).

func (*Client) Complete

func (r *Client) Complete(ctx context.Context, key ops.SiteOperationKey) error

Complete manually completes the active operation

func (*Client) ExecutePhase

func (r *Client) ExecutePhase(ctx context.Context, phase Phase) error

ExecutePhase executes the specified phase

func (*Client) RollbackPhase

func (r *Client) RollbackPhase(ctx context.Context, phase Phase) error

RollbackPhase rolls back the specified phase

func (*Client) Run

func (r *Client) Run(ctx context.Context) error

Run starts the service operation and runs the loop to fetch and display operation progress

func (*Client) SetPhase

func (r *Client) SetPhase(ctx context.Context, phase Phase, state string) error

SetPhase sets the specified phase state without executing it

func (*Client) Stop

func (r *Client) Stop(ctx context.Context) error

Stop signals the service to stop and invokes the abort handler Implements signals.Stopper

type CompletionHandler

type CompletionHandler func(context.Context, pb.ProgressResponse_Status) error

CompletionHandler describes a functional handler for tasks to run after operation is complete

type Config

type Config struct {
	// FieldLogger specifies the logger
	log.FieldLogger
	// Printer specifies the message output sink for progress messages
	utils.Printer
	// InterruptHandler specifies the interruption handler to register with
	*signals.InterruptHandler
	// ConnectStrategy specifies the connection to setup/connect to the service
	ConnectStrategy
	// Lifecycle specifies the implementation of exit strategies after operation
	// completion
	Lifecycle Lifecycle
}

Config describes the configuration of the installer client

type ConnectStrategy

type ConnectStrategy interface {
	// contains filtered or unexported methods
}

ConnectStrategy abstracts a way to connect to the installer service

type InstallerStrategy

type InstallerStrategy struct {
	// FieldLogger specifies the logger
	log.FieldLogger
	// Args specifies the service command line including the executable
	Args []string
	// ApplicationDir specifies the directory with installer files
	ApplicationDir string
	// Validate specifies the environment validation function.
	// The service will only be installed when Validate returns nil
	Validate func() error
	// SocketPath specifies the path to the service socket file
	SocketPath string
	// ServicePath specifies the absolute path to the service unit
	ServicePath string
	// ServiceName specifies the name of the service unit. It must be the same
	// service specified with ServicePath
	ServiceName string
	// ConnectTimeout specifies the maximum amount of time to wait for
	// installer service connection.
	ConnectTimeout time.Duration
}

InstallerStrategy implements the strategy that creates a new installer service before attempting to connect. This strategy also validates the environment before attempting to set up the service to prevent from running the installer on a system already part of the cluster

type Lifecycle

type Lifecycle interface {

	// HandleStatus executes status-specific tasks after an operation is completed
	HandleStatus(context.Context, *Client, installpb.ProgressResponse_Status, error) error
	// Complete executes tasks after the operation has been completed successfully
	Complete(context.Context, *Client, installpb.ProgressResponse_Status) error
	// Abort handles clean up of state files and directories
	// the installer maintains throughout the operation
	Abort(context.Context, *Client) error
	// contains filtered or unexported methods
}

Lifecycle handles different exit strategies for an operation after completion.

type NoopLifecycle

type NoopLifecycle struct{}

NoopLifecycle implements a client lifecycle that does nothing

func (*NoopLifecycle) Abort

Abort is a no-op

func (*NoopLifecycle) Complete

Complete is a no-op

func (*NoopLifecycle) HandleStatus

func (r *NoopLifecycle) HandleStatus(ctx context.Context, c *Client, status installpb.ProgressResponse_Status, err error) error

HandleStatus implements status handling by propagating specified error to the caller. If the error indicates end-of-stream, it is ignored

type Phase

type Phase struct {
	// ID specifies the phase ID
	ID string
	// Force defines whether the phase execution is forced regardless
	// of its state
	Force bool
	// Key identifies the active operation
	Key ops.SiteOperationKey
}

Phase groups parameters for executing/rolling back a phase

func (Phase) IsResume

func (r Phase) IsResume() bool

IsResume returns true if this is a resume operation

type ResumeStrategy

type ResumeStrategy struct {
	// FieldLogger specifies the logger
	log.FieldLogger
	// SocketPath specifies the path to the service socket file
	SocketPath string
	// ServicePath specifies the absolute path to the service unit
	ServicePath string
	// ServiceName specifies the name of the installer service. Must reference
	// the same service specified with ServicePath
	ServiceName string
	// ConnectTimeout specifies the maximum amount of time to wait for
	// installer service connection. Defaults to defaults.ServiceConnectTimeout
	// if unspecified
	ConnectTimeout time.Duration
}

ResumeStrategy implements the strategy to connect to the existing installer service

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL