github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/core/model/generation.go (about)

     1  // Copyright 2018 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package model
     5  
     6  import (
     7  	"time"
     8  
     9  	"github.com/juju/errors"
    10  )
    11  
    12  // TODO (manadart 2019-04-21) Change the nomenclature here to indicate "branch"
    13  // instead of "generation", and remove Current/Next.
    14  
    15  // GenerationMaster is used to indicate the main model configuration,
    16  // i.e. that not dealing with in-flight branches.
    17  const GenerationMaster = "master"
    18  
    19  // ValidateBranchName returns an error if the input name is not suitable for
    20  // identifying a new in-flight branch.
    21  func ValidateBranchName(name string) error {
    22  	if name == "" {
    23  		return errors.NotValidf("empty branch name")
    24  	}
    25  	if name == GenerationMaster {
    26  		return errors.NotValidf("branch name %q", GenerationMaster)
    27  	}
    28  	return nil
    29  }
    30  
    31  // GenerationUnits indicates which units from an application are and are not
    32  // tracking a model branch.
    33  type GenerationUnits struct {
    34  	// UnitsTracking is the names of application units that have been set to
    35  	// track the branch.
    36  	UnitsTracking []string `yaml:"tracking,omitempty"`
    37  
    38  	// UnitsPending is the names of application units that are still tracking
    39  	// the master generation.
    40  	UnitsPending []string `yaml:"incomplete,omitempty"`
    41  }
    42  
    43  // GenerationApplication represents changes to an application
    44  // made under a generation.
    45  type GenerationApplication struct {
    46  	// ApplicationsName is the name of the application.
    47  	ApplicationName string `yaml:"application"`
    48  
    49  	// UnitProgress is summary information about units tracking the branch.
    50  	UnitProgress string `yaml:"progress,omitempty"`
    51  
    52  	// UnitDetail specifies which units are and are not tracking the branch.
    53  	UnitDetail *GenerationUnits `yaml:"units,omitempty"`
    54  
    55  	// Config changes are the differing configuration values between this
    56  	// generation and the current.
    57  	// TODO (manadart 2018-02-22) This data-type will evolve as more aspects
    58  	// of the application are made generational.
    59  	ConfigChanges map[string]interface{} `yaml:"config"`
    60  }
    61  
    62  // Generation represents detail of a model generation including config changes.
    63  type Generation struct {
    64  	// Created is the formatted time at generation creation.
    65  	Created string `yaml:"created"`
    66  
    67  	// Created is the user who created the generation.
    68  	CreatedBy string `yaml:"created-by"`
    69  
    70  	// Applications is a collection of applications with changes in this
    71  	// generation including advanced units and modified configuration.
    72  	Applications []GenerationApplication `yaml:"applications"`
    73  }
    74  
    75  // GenerationCommit represents a model generation's commit details.
    76  type GenerationCommit struct {
    77  	// BranchName uniquely identifies a branch *amongst in-flight branches*.
    78  	BranchName string `yaml:"branch"`
    79  
    80  	// Created is the Unix timestamp at generation creation.
    81  	Completed time.Time `yaml:"completed"`
    82  
    83  	// Created is the user who created the generation.
    84  	CompletedBy string `yaml:"completed-by"`
    85  
    86  	// Created is the Unix timestamp at generation creation.
    87  	Created time.Time `yaml:"created,omitempty"`
    88  
    89  	// Created is the user who created the generation.
    90  	CreatedBy string `yaml:"created-by,omitempty"`
    91  
    92  	// GenerationId is the id .
    93  	GenerationId int `yaml:"generation-id,omitempty"`
    94  
    95  	// Applications holds the collection of application changes
    96  	// made under this generation.
    97  	Applications []GenerationApplication `yaml:"applications,omitempty"`
    98  }
    99  
   100  // GenerationSummaries is a type alias for a representation
   101  // of changes-by-generation.
   102  type GenerationSummaries = map[string]Generation
   103  
   104  // GenerationCommits is a type alias for a representation of each commit.
   105  // Keyed by the generation id
   106  type GenerationCommits = []GenerationCommit