github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/payload/payload.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package payload
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"gopkg.in/juju/charm.v6-unstable"
     9  )
    10  
    11  // Payload holds information about a charm payload.
    12  type Payload struct {
    13  	charm.PayloadClass
    14  
    15  	// ID is a unique string identifying the payload to
    16  	// the underlying technology.
    17  	ID string
    18  
    19  	// TODO(ericsnow) Use the payload.Status type instead of a string?
    20  
    21  	// Status is the Juju-level status of the payload.
    22  	Status string
    23  
    24  	// Labels are labels associated with the payload.
    25  	Labels []string
    26  
    27  	// Unit identifies the Juju unit associated with the payload.
    28  	Unit string
    29  }
    30  
    31  // FullID composes a unique ID for the payload (relative to the unit/charm).
    32  func (p Payload) FullID() string {
    33  	return BuildID(p.PayloadClass.Name, p.ID)
    34  }
    35  
    36  // Validate checks the payload info to ensure it is correct.
    37  func (p Payload) Validate() error {
    38  	if err := p.PayloadClass.Validate(); err != nil {
    39  		return errors.NewNotValid(err, "")
    40  	}
    41  
    42  	if p.ID == "" {
    43  		return errors.NotValidf("missing ID")
    44  	}
    45  
    46  	if err := ValidateState(p.Status); err != nil {
    47  		return errors.Trace(err)
    48  	}
    49  
    50  	// TODO(ericsnow) Do not require Unit to be set?
    51  	if p.Unit == "" {
    52  		return errors.NotValidf("missing Unit")
    53  	}
    54  
    55  	return nil
    56  }
    57  
    58  // FullPayloadInfo completely describes a charm payload, including
    59  // some information that may be implied from the minimal Payload data.
    60  type FullPayloadInfo struct {
    61  	Payload
    62  
    63  	// Machine identifies the Juju machine associated with the payload.
    64  	Machine string
    65  }
    66  
    67  // Result is a struct that ties an error to a payload ID.
    68  type Result struct {
    69  	// ID is the ID of the payload that this result applies to.
    70  	ID string
    71  	// Payload holds the info about the payload, if available.
    72  	Payload *FullPayloadInfo
    73  	// NotFound indicates that the payload was not found in Juju.
    74  	NotFound bool
    75  	// Error is the error associated with this result (if any).
    76  	Error error
    77  }