Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add state model for service directory #3643

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apiserver/crossmodel/crossmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/crossmodel"
"github.com/juju/juju/model/crossmodel"
"github.com/juju/juju/state"
)

Expand Down
2 changes: 1 addition & 1 deletion apiserver/crossmodel/crossmodel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

apicrossmodel "github.com/juju/juju/apiserver/crossmodel"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/crossmodel"
"github.com/juju/juju/model/crossmodel"
)

type crossmodelSuite struct {
Expand Down
2 changes: 1 addition & 1 deletion apiserver/params/crossmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type CrossModelOffer struct {
// Endpoints list of service's endpoints that are being offered.
Endpoints []string `json:"endpoints"`

// URL is the location where these endpoitns will be accessible from.
// URL is the location where these endpoints will be accessible from.
URL string `json:"url"`

// Users is the list of user tags that are given permission to these endpoints.
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/crossmodel/offer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/cmd/envcmd"
"github.com/juju/juju/crossmodel"
"github.com/juju/juju/model/crossmodel"
)

const (
Expand Down
21 changes: 0 additions & 21 deletions crossmodel/interface.go

This file was deleted.

81 changes: 81 additions & 0 deletions model/crossmodel/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package crossmodel

import (
"fmt"

"github.com/juju/names"
"gopkg.in/juju/charm.v6-unstable"
)

// TODO(wallyworld) - remove this ASAP and use ServiceOffer
// Offer holds information about service's offer.
type Offer struct {
// Service has service's tag.
Service names.ServiceTag

// Endpoints list of service's endpoints that are being offered.
Endpoints []string

// URL is the location where these endpoints will be accessible from.
URL string

// Users is the list of user tags that are given permission to these endpoints.
Users []names.UserTag
}

// ServiceOffer represents the state of a service hosted
// in an external (remote) environment.
type ServiceOffer struct {
// ServiceURL is the URL used to locate the offer in a directory.
ServiceURL string

// ServiceName is the name of the service.
ServiceName string

// ServiceDescription is a description of the service's functionality,
// typically copied from the charm metadata.
ServiceDescription string

// Endpoints are the charm endpoints supported by the service.
Endpoints []charm.Relation

// SourceEnvUUID is the UUID of the environment hosting the service.
SourceEnvUUID string

// SourceLabel is a user friendly name for the source environment.
SourceLabel string
}

// String returns the directory record name.
func (s *ServiceOffer) String() string {
return fmt.Sprintf("%s-%s", s.SourceEnvUUID, s.ServiceName)
}

// ServiceOfferFilter is used to query offers in a service directory.
// We allow filtering on any of the service offer attributes plus
// users allowed to consume the service.
type ServiceOfferFilter struct {
ServiceOffer

// AllowedUsers are the users allowed to consume the service.
AllowedUsers []string
}

// A ServiceDirectory holds service offers from external environments.
type ServiceDirectory interface {

// AddOffer adds a new service offer to the directory.
AddOffer(offer ServiceOffer) error

// UpdateOffer replaces an existing offer at the same URL.
UpdateOffer(offer ServiceOffer) error

// List offers returns the offers satisfying the specified filter.
ListOffers(filter ...ServiceOfferFilter) ([]ServiceOffer, error)

// Remove removes the service offer at the specified URL.
Remove(url string) error
}
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions state/allcollections.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ func allCollections() collectionSchema {
// was implemented.
actionresultsC: {global: true},

// This collection holds information about services that have been
// offered (exported) for use in other models.
serviceOffersC: {
global: true,
indexes: []mgo.Index{{
Key: []string{"url"},
}},
},

// -----------------

// Local collections
Expand Down Expand Up @@ -369,6 +378,7 @@ const (
restoreInfoC = "restoreInfo"
sequenceC = "sequence"
servicesC = "services"
serviceOffersC = "serviceoffers"
settingsC = "settings"
settingsrefsC = "settingsrefs"
stateServersC = "stateServers"
Expand Down
9 changes: 9 additions & 0 deletions state/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"gopkg.in/mgo.v2/bson"
"gopkg.in/mgo.v2/txn"

"github.com/juju/juju/model/crossmodel"
"github.com/juju/juju/mongo"
"github.com/juju/juju/network"
"github.com/juju/juju/testcharms"
Expand Down Expand Up @@ -86,6 +87,14 @@ func newRunnerForHooks(st *State) jujutxn.Runner {
return runner
}

func OfferAtURL(sd crossmodel.ServiceDirectory, url string) (*serviceOfferDoc, error) {
return sd.(*serviceDirectory).offerAtURL(url)
}

func MakeServiceOfferDoc(sd crossmodel.ServiceDirectory, url string, offer crossmodel.ServiceOffer) serviceOfferDoc {
return sd.(*serviceDirectory).makeServiceOfferDoc(offer)
}

// SetPolicy updates the State's policy field to the
// given Policy, and returns the old value.
func SetPolicy(st *State, p Policy) Policy {
Expand Down