Skip to content

Commit

Permalink
Remove older API versions supporting remote spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
nvinuesa committed Mar 22, 2024
1 parent 14d6a6f commit 2a8cc8e
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 177 deletions.
4 changes: 2 additions & 2 deletions api/facadeversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var facadeVersions = facades.FacadeVersions{
"AllWatcher": {3},
"Annotations": {2},
"Application": {19, 20},
"ApplicationOffers": {4, 5},
"ApplicationOffers": {5},
"ApplicationScaler": {1},
"Backups": {3},
"Block": {2},
Expand All @@ -54,7 +54,7 @@ var facadeVersions = facades.FacadeVersions{
"CredentialManager": {1},
"CredentialValidator": {2},
"CrossController": {1},
"CrossModelRelations": {2, 3},
"CrossModelRelations": {3},
"CrossModelSecrets": {1},
"Deployer": {1},
"DiskManager": {2},
Expand Down
2 changes: 1 addition & 1 deletion apiserver/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ func (s *loginSuite) TestAnonymousModelLogin(c *gc.C) {
c.Assert(result.ControllerTag, gc.Equals, s.ControllerModel(c).State().ControllerTag().String())
c.Assert(result.ModelTag, gc.Equals, names.NewModelTag(s.ControllerModelUUID()).String())
c.Assert(result.Facades, jc.DeepEquals, []params.FacadeVersions{
{Name: "CrossModelRelations", Versions: []int{2, 3}},
{Name: "CrossModelRelations", Versions: []int{3}},
{Name: "CrossModelSecrets", Versions: []int{1}},
{Name: "NotifyWatcher", Versions: []int{1}},
{Name: "OfferStatusWatcher", Versions: []int{1}},
Expand Down
17 changes: 0 additions & 17 deletions apiserver/facades/client/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -2071,23 +2071,6 @@ func (api *APIBase) consumeOne(ctx context.Context, arg params.ConsumeApplicatio
return err
}

// Consume adds remote applications to the model without creating any
// relations.
func (api *APIv19) Consume(ctx context.Context, args params.ConsumeApplicationArgsV4) (params.ErrorResults, error) {
var consumeApplicationArgs []params.ConsumeApplicationArgV5
for _, arg := range args.Args {
consumeApplicationArgs = append(consumeApplicationArgs, params.ConsumeApplicationArgV5{
Macaroon: arg.Macaroon,
ControllerInfo: arg.ControllerInfo,
ApplicationAlias: arg.ApplicationAlias,
ApplicationOfferDetailsV5: arg.ApplicationOfferDetailsV5,
})
}
return api.APIv20.Consume(ctx, params.ConsumeApplicationArgsV5{
Args: consumeApplicationArgs,
})
}

// saveRemoteApplication saves the details of the specified remote application and its endpoints
// to the state model so relations to the remote application can be created.
func (api *APIBase) saveRemoteApplication(
Expand Down
25 changes: 0 additions & 25 deletions apiserver/facades/client/applicationoffers/applicationoffers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ type OffersAPIv5 struct {
authContext *commoncrossmodel.AuthContext
}

// OffersAPIv4 implements the cross model interface and is the concrete
// implementation of the api end point.
type OffersAPIv4 struct {
OffersAPIv5
}

// createAPI returns a new application offers OffersAPI facade.
func createOffersAPI(
getApplicationOffers func(interface{}) jujucrossmodel.ApplicationOffers,
Expand Down Expand Up @@ -164,25 +158,6 @@ func (api *OffersAPIv5) ListApplicationOffers(ctx context.Context, filters param
return result, nil
}

// ListApplicationOffers gets deployed details about application offers that match given filter.
// The results contain details about the deployed applications such as connection count.
func (api *OffersAPIv4) ListApplicationOffers(ctx context.Context, filters params.OfferFilters) (params.QueryApplicationOffersResultsV4, error) {
res, err := api.OffersAPIv5.ListApplicationOffers(ctx, filters)
if err != nil {
return params.QueryApplicationOffersResultsV4{}, errors.Trace(err)
}
resultsV4 := make([]params.ApplicationOfferAdminDetailsV4, len(res.Results))
for i, result := range res.Results {
resultsV4[i] = params.ApplicationOfferAdminDetailsV4{
ApplicationOfferAdminDetailsV5: result,
}
}

return params.QueryApplicationOffersResultsV4{
Results: resultsV4,
}, nil
}

// ModifyOfferAccess changes the application offer access granted to users.
func (api *OffersAPIv5) ModifyOfferAccess(ctx context.Context, args params.ModifyOfferAccessRequest) (result params.ErrorResults, _ error) {
result = params.ErrorResults{
Expand Down
14 changes: 0 additions & 14 deletions apiserver/facades/client/applicationoffers/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,11 @@ import (

// Register is called to expose a package of facades onto a given registry.
func Register(registry facade.FacadeRegistry) {
registry.MustRegister("ApplicationOffers", 4, func(stdCtx context.Context, ctx facade.ModelContext) (facade.Facade, error) {
return newOffersAPIV4(ctx)
}, reflect.TypeOf((*OffersAPIv4)(nil)))
registry.MustRegister("ApplicationOffers", 5, func(stdCtx context.Context, ctx facade.ModelContext) (facade.Facade, error) {
return newOffersAPI(ctx)
}, reflect.TypeOf((*OffersAPIv5)(nil)))
}

// newOffersAPIV4 returns a new application offers OffersAPIV4 facade.
func newOffersAPIV4(ctx facade.ModelContext) (*OffersAPIv4, error) {
offersAPI, err := newOffersAPI(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &OffersAPIv4{
*offersAPI,
}, nil
}

// newOffersAPI returns a new application offers OffersAPI facade.
func newOffersAPI(facadeContext facade.ModelContext) (*OffersAPIv5, error) {
serviceFactory := facadeContext.ServiceFactory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ type CrossModelRelationsAPIv3 struct {
logger loggo.Logger
}

// CrossModelRelationsAPIv2 provides access to the CrossModelRelations API facade.
type CrossModelRelationsAPIv2 struct {
*CrossModelRelationsAPIv3
}

// NewCrossModelRelationsAPI returns a new server-side CrossModelRelationsAPI facade.
func NewCrossModelRelationsAPI(
st CrossModelRelationsState,
Expand Down Expand Up @@ -169,37 +164,6 @@ func (api *CrossModelRelationsAPIv3) PublishRelationChanges(
return results, nil
}

// RegisterRemoteRelations sets up the model to participate
// in the specified relations. This operation is idempotent.
func (api *CrossModelRelationsAPIv2) RegisterRemoteRelations(
ctx context.Context,
relations params.RegisterRemoteRelationArgsV2,
) (params.RegisterRemoteRelationResults, error) {
results := params.RegisterRemoteRelationResults{
Results: make([]params.RegisterRemoteRelationResult, len(relations.Relations)),
}
for i, relation := range relations.Relations {
id, err := api.registerRemoteRelation(ctx,
params.RegisterRemoteRelationArg{
ApplicationToken: relation.ApplicationToken,
SourceModelTag: relation.SourceModelTag,
RelationToken: relation.RelationToken,
RemoteEndpoint: relation.RemoteEndpoint,
// RemoteSpace isn't used so we can simply
// ignore it.
OfferUUID: relation.OfferUUID,
LocalEndpointName: relation.LocalEndpointName,
ConsumeVersion: relation.ConsumeVersion,
Macaroons: relation.Macaroons,
BakeryVersion: relation.BakeryVersion,
},
)
results.Results[i].Result = id
results.Results[i].Error = apiservererrors.ServerError(err)
}
return results, nil
}

// RegisterRemoteRelations sets up the model to participate
// in the specified relations. This operation is idempotent.
func (api *CrossModelRelationsAPIv3) RegisterRemoteRelations(
Expand Down
15 changes: 0 additions & 15 deletions apiserver/facades/controller/crossmodelrelations/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"context"
"reflect"

"github.com/juju/errors"

"github.com/juju/juju/apiserver/common"
commoncrossmodel "github.com/juju/juju/apiserver/common/crossmodel"
"github.com/juju/juju/apiserver/common/firewall"
Expand All @@ -18,24 +16,11 @@ import (

// Register is called to expose a package of facades onto a given registry.
func Register(registry facade.FacadeRegistry) {
registry.MustRegister("CrossModelRelations", 2, func(stdCtx context.Context, ctx facade.ModelContext) (facade.Facade, error) {
return newStateCrossModelRelationsAPIV2(ctx) // Adds WatchRelationChanges, removes WatchRelationUnits
}, reflect.TypeOf((*CrossModelRelationsAPIv2)(nil)))
registry.MustRegister("CrossModelRelations", 3, func(stdCtx context.Context, ctx facade.ModelContext) (facade.Facade, error) {
return newStateCrossModelRelationsAPI(ctx) // Removes remote spaces
}, reflect.TypeOf((*CrossModelRelationsAPIv3)(nil)))
}

// newStateCrossModelRelationsAPIV2 creates a new server-side CrossModelRelations API facade
// backed by global state.
func newStateCrossModelRelationsAPIV2(ctx facade.ModelContext) (*CrossModelRelationsAPIv2, error) {
api, err := newStateCrossModelRelationsAPI(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &CrossModelRelationsAPIv2{api}, nil
}

// newStateCrossModelRelationsAPI creates a new server-side CrossModelRelations API facade
// backed by global state.
func newStateCrossModelRelationsAPI(ctx facade.ModelContext) (*CrossModelRelationsAPIv3, error) {
Expand Down
10 changes: 0 additions & 10 deletions apiserver/restrict_anonymous_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,9 @@ func (s *restrictAnonymousSuite) SetUpSuite(c *gc.C) {
s.root = apiserver.TestingAnonymousRoot()
}

func (s *restrictAnonymousSuite) TestAllowed(c *gc.C) {
s.assertMethod(c, "CrossModelRelations", 2, "RegisterRemoteRelations")
}

func (s *restrictAnonymousSuite) TestNotAllowed(c *gc.C) {
caller, err := s.root.FindMethod("Client", clientFacadeVersion, "FullStatus")
c.Assert(err, gc.ErrorMatches, `facade "Client" not supported for anonymous API connections`)
c.Assert(err, jc.ErrorIs, errors.NotSupported)
c.Assert(caller, gc.IsNil)
}

func (s *restrictAnonymousSuite) assertMethod(c *gc.C, facadeName string, version int, method string) {
caller, err := s.root.FindMethod(facadeName, version, method)
c.Check(err, jc.ErrorIsNil)
c.Check(caller, gc.NotNil)
}
2 changes: 1 addition & 1 deletion apiserver/restrict_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s *restrictControllerSuite) TestAllowed(c *gc.C) {
s.assertMethod(c, "Pinger", pingerFacadeVersion, "Ping")
s.assertMethod(c, "Bundle", 8, "GetChangesMapArgs")
s.assertMethod(c, "HighAvailability", highAvailabilityFacadeVersion, "EnableHA")
s.assertMethod(c, "ApplicationOffers", 4, "ApplicationOffers")
s.assertMethod(c, "ApplicationOffers", 5, "ApplicationOffers")
}

func (s *restrictControllerSuite) TestNotAllowed(c *gc.C) {
Expand Down
56 changes: 0 additions & 56 deletions rpc/params/crossmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ type ApplicationOfferDetailsV5 struct {
Users []OfferUserDetails `json:"users,omitempty"`
}

// ApplicationOfferDetailsV4 represents an application offering from an external model.
type ApplicationOfferDetailsV4 struct {
ApplicationOfferDetailsV5
Spaces []RemoteSpace `json:"spaces,omitempty"`
Bindings map[string]string `json:"bindings,omitempty"`
}

// OfferUserDetails represents an offer consumer and their permission on the offer.
type OfferUserDetails struct {
UserName string `json:"user"`
Expand All @@ -102,14 +95,6 @@ type ApplicationOfferAdminDetailsV5 struct {
Connections []OfferConnection `json:"connections,omitempty"`
}

// ApplicationOfferAdminDetailsV4 represents an application offering,
// including details about how it has been deployed.
type ApplicationOfferAdminDetailsV4 struct {
ApplicationOfferAdminDetailsV5
Spaces []RemoteSpace `json:"spaces,omitempty"`
Bindings map[string]string `json:"bindings,omitempty"`
}

// OfferConnection holds details about a connection to an offer.
type OfferConnection struct {
SourceModelTag string `json:"source-model-tag"`
Expand All @@ -126,12 +111,6 @@ type QueryApplicationOffersResultsV5 struct {
Results []ApplicationOfferAdminDetailsV5 `json:"results"`
}

// QueryApplicationOffersResultsV4 is a result of searching application offers.
type QueryApplicationOffersResultsV4 struct {
// Results contains application offers matching each filter.
Results []ApplicationOfferAdminDetailsV4 `json:"results"`
}

// AddApplicationOffers is used when adding offers to an application directory.
type AddApplicationOffers struct {
Offers []AddApplicationOffer
Expand Down Expand Up @@ -161,15 +140,6 @@ type RemoteEndpoint struct {
Limit int `json:"limit"`
}

// RemoteSpace represents a space in some remote model.
type RemoteSpace struct {
CloudType string `json:"cloud-type"`
Name string `json:"name"`
ProviderId string `json:"provider-id"`
ProviderAttributes map[string]interface{} `json:"provider-attributes"`
Subnets []Subnet `json:"subnets"`
}

// ApplicationOfferResult is a result of querying a remote
// application offer based on its URL.
type ApplicationOfferResult struct {
Expand Down Expand Up @@ -211,23 +181,11 @@ type ConsumeApplicationArgV5 struct {
ApplicationAlias string `json:"application-alias,omitempty"`
}

// ConsumeApplicationArgV4 holds the arguments for consuming a remote application.
type ConsumeApplicationArgV4 struct {
ConsumeApplicationArgV5
Spaces []RemoteSpace `json:"spaces,omitempty"`
Bindings map[string]string `json:"bindings,omitempty"`
}

// ConsumeApplicationArgsV5 is a collection of arg for consuming applications.
type ConsumeApplicationArgsV5 struct {
Args []ConsumeApplicationArgV5 `json:"args,omitempty"`
}

// ConsumeApplicationArgsV4 is a collection of arg for consuming applications.
type ConsumeApplicationArgsV4 struct {
Args []ConsumeApplicationArgV4 `json:"args,omitempty"`
}

// TokenResult holds a token and an error.
type TokenResult struct {
Token string `json:"token,omitempty"`
Expand Down Expand Up @@ -572,25 +530,11 @@ type RegisterRemoteRelationArg struct {
BakeryVersion bakery.Version `json:"bakery-version,omitempty"`
}

// RegisterRemoteRelationArg holds attributes used to register a remote relation.
type RegisterRemoteRelationArgV2 struct {
RegisterRemoteRelationArg

// RemoteSpace contains provider-level info about the space the
// endpoint is bound to in the remote model.
RemoteSpace RemoteSpace `json:"remote-space"`
}

// RegisterRemoteRelationArgs holds args used to add remote relations.
type RegisterRemoteRelationArgs struct {
Relations []RegisterRemoteRelationArg `json:"relations"`
}

// RegisterRemoteRelationArgsV2 holds args used to add remote relations.
type RegisterRemoteRelationArgsV2 struct {
Relations []RegisterRemoteRelationArgV2 `json:"relations"`
}

// RegisterRemoteRelationResult holds a remote relation details and an error.
type RegisterRemoteRelationResult struct {
Result *RemoteRelationDetails `json:"result,omitempty"`
Expand Down

0 comments on commit 2a8cc8e

Please sign in to comment.