github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/core/cache/application.go (about)

     1  // Copyright 2018 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package cache
     5  
     6  import (
     7  	"sync"
     8  
     9  	"github.com/juju/pubsub"
    10  )
    11  
    12  func newApplication(metrics *ControllerGauges, hub *pubsub.SimpleHub) *Application {
    13  	m := &Application{
    14  		metrics: metrics,
    15  		hub:     hub,
    16  	}
    17  	return m
    18  }
    19  
    20  // Application represents an application in a model.
    21  type Application struct {
    22  	// Link to model?
    23  	metrics *ControllerGauges
    24  	hub     *pubsub.SimpleHub
    25  	mu      sync.Mutex
    26  
    27  	details    ApplicationChange
    28  	configHash string
    29  }
    30  
    31  func (m *Application) setDetails(details ApplicationChange) {
    32  	m.mu.Lock()
    33  	defer m.mu.Unlock()
    34  	m.details = details
    35  
    36  	configHash, err := hash(details.Config)
    37  	if err != nil {
    38  		logger.Errorf("invariant error - application config should be yaml serializable and hashable, %v", err)
    39  		configHash = ""
    40  	}
    41  	if configHash != m.configHash {
    42  		m.configHash = configHash
    43  		// TODO: publish config change...
    44  	}
    45  }