github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/resource/state/state.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package state
     5  
     6  import (
     7  	"time"
     8  
     9  	"github.com/juju/loggo"
    10  )
    11  
    12  var logger = loggo.GetLogger("juju.resource.state")
    13  
    14  // Persistence is the state persistence functionality needed for resources.
    15  type Persistence interface {
    16  	resourcePersistence
    17  }
    18  
    19  // Storage is the state storage functionality needed for resources.
    20  type Storage interface {
    21  	resourceStorage
    22  }
    23  
    24  // RawState defines the functionality needed from state.State for resources.
    25  type RawState interface {
    26  	rawState
    27  
    28  	// Persistence exposes the state data persistence needed for resources.
    29  	Persistence() Persistence
    30  
    31  	// Storage exposes the state blob storage needed for resources.
    32  	Storage() Storage
    33  }
    34  
    35  // State exposes the state functionality needed for resources.
    36  type State struct {
    37  	*resourceState
    38  }
    39  
    40  // NewState returns a new State for the given raw Juju state.
    41  func NewState(raw RawState) *State {
    42  	logger.Tracef("wrapping state for resources")
    43  
    44  	persist := raw.Persistence()
    45  
    46  	storage := raw.Storage()
    47  
    48  	st := &State{
    49  		resourceState: &resourceState{
    50  			persist:      persist,
    51  			raw:          raw,
    52  			storage:      storage,
    53  			newPendingID: newPendingID,
    54  			currentTimestamp: func() time.Time {
    55  				// TODO(perrito666) 2016-05-02 lp:1558657
    56  				return time.Now().UTC()
    57  			},
    58  		},
    59  	}
    60  	return st
    61  }