migrations

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var V1Migration = repo.NewMigration(
	repo.Version1,
	repo.Version2,
	func(r repo.FsRepo) error {
		configExist, err := configExists(r)
		if err != nil {
			return err
		}
		if !configExist {
			return nil
		}
		v, _, err := readConfig(r)
		if err != nil {
			return err
		}

		doWrite := false
		if v.Get(legacyIPFSSwarmAddressesKey) != nil {
			v.Set(legacyIPFSSwarmAddressesKey, []string{})
			doWrite = true
		}
		if v.Get(legacyBootstrapAddressesKey) != nil {
			v.Set(legacyBootstrapAddressesKey, []string{})
			doWrite = true
		}
		if doWrite {
			return v.WriteConfig()
		}
		return nil
	})
View Source
var V2Migration = repo.NewMigration(
	repo.Version2,
	repo.Version3,
	func(r repo.FsRepo) error {
		v, fileCfg, err := readConfig(r)
		if err != nil {
			return err
		}
		repoPath, err := r.Path()
		if err != nil {
			return err
		}

		opts := []config_legacy.Option{config_legacy.WithValues(viper.AllSettings())}
		if _, err := os.Stat(filepath.Join(repoPath, config_legacy.FileName)); err != nil {

			if !errors.Is(err, os.ErrNotExist) {
				return fmt.Errorf("loading config from repo: %w", err)
			}
		} else {
			opts = append(opts, config_legacy.WithPaths(filepath.Join(repoPath, config_legacy.FileName)))
		}
		c, err := config_legacy.New(
			opts...,
		)
		if err != nil {
			return err
		}

		r.EnsureRepoPathsConfigured(c)
		resolvedCfg, err := c.Current()
		if err != nil {
			return err
		}
		libp2pNodeID, err := getLibp2pNodeID(repoPath)
		if err != nil {
			return err
		}

		doWrite := false
		var logMessage strings.Builder
		set := func(key string, value interface{}) {
			v.Set(key, value)
			logMessage.WriteString(fmt.Sprintf("\n%s:\t%v", key, value))
			doWrite = true
		}

		if fileCfg.Node.Compute.ExecutionStore.Path == "" {

			executionStore := resolvedCfg.Node.Compute.ExecutionStore

			if executionStore.Path == "" {
				executionStore.Path = filepath.Join(repoPath, "compute_store", "executions.db")
			}

			legacyStoreName := filepath.Join(repoPath, libp2pNodeID+"-compute")
			newStorePath := filepath.Dir(executionStore.Path)
			if _, err := os.Stat(legacyStoreName); err == nil {
				if err := os.Rename(legacyStoreName, newStorePath); err != nil {
					return err
				}
			} else if err = os.MkdirAll(newStorePath, util.OS_USER_RWX); err != nil {
				return err
			}
			set(legacy_types.NodeComputeExecutionStore, executionStore)
		}

		if fileCfg.Node.Requester.JobStore.Path == "" {

			jobStore := resolvedCfg.Node.Requester.JobStore

			if jobStore.Path == "" {
				jobStore.Path = filepath.Join(repoPath, "orchestrator_store", "jobs.db")
			}

			legacyStoreName := filepath.Join(repoPath, libp2pNodeID+"-requester")
			newStorePath := filepath.Dir(jobStore.Path)
			if _, err := os.Stat(legacyStoreName); err == nil {
				if err := os.Rename(legacyStoreName, newStorePath); err != nil {
					return err
				}
			} else if err = os.MkdirAll(newStorePath, util.OS_USER_RWX); err != nil {
				return err
			}
			set(legacy_types.NodeRequesterJobStore, jobStore)
		}

		if fileCfg.Node.Name == "" {
			set(legacy_types.NodeName, libp2pNodeID)
		}

		if doWrite {
			return v.WriteConfig()
		}
		return nil
	})

V2Migration updates the repo so that nodeID is no longer part of the execution and job store paths. It does the following: - Generates and persists the nodeID in the config if it is missing, which is the case for v2 repos - Adds the execution and job store paths to the config if they are missing, which is the case for v3 repos - Renames the execution and job store directories to the new name if they exist

V3Migration updates the repo, replacing repo.version and update.json with system_metadata.yaml. It does the following: - Creates system_metadata.yaml with repo version 4. - Sets the last update check time in system_metadata.yaml to Unix time zero. - If an installationID is present in the config, its value is persisted to system_metadata.yaml. - Removes update.json if the file is present. - Removes repo.version. - Creates a new directory .bacalhau/orchestrator. - Moves contents of .bacalhau/orchestrator_store to .bacalhau/orchestrator and renames jobs.db to state_boltdb.db. - Removes .bacalhau/orchestrator_store. - Creates a new directory .bacalhau/compute. - Moves executions.db from .bacalhau/compute_store to .bacalhau/compute/state_boltdb.db. - Creates a new directory .bacalhau/compute/executions. - Moves contents of .bacalhau/execution_store to .bacalhau/compute/executions. - Removes ./bacalhau/execution_store. - If a user has configured a custom user key path, the configured value is copied to .bacalhau/user_id.pem. - If a user has configured a custom auth tokens path, the configured value is copied to .bacalhau/tokens.json.

Functions

func V3MigrationWithConfig added in v1.5.0

func V3MigrationWithConfig(globalCfg system.GlobalConfig) repo.Migration

V3MigrationWithConfig TODO: This is a very complex function that should be simplified and split

Types

This section is empty.

Jump to

Keyboard shortcuts

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