Skip to content

Commit

Permalink
Css 4116/backport crossmodel queries (#964)
Browse files Browse the repository at this point in the history
* Model status parser

* Bring in API definition

* Bring in storage facade calls

* Update jimmtest api

* Add api call

* Add API params

* Facade call

* Initial backport of parser

* Fix relation test

* PR comments

* Refactor according to PR comments

* pr comments
  • Loading branch information
ale8k authored Jun 26, 2023
1 parent 5a2af0d commit 46c42ea
Show file tree
Hide file tree
Showing 11 changed files with 1,462 additions and 19 deletions.
9 changes: 9 additions & 0 deletions api/jimm.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,12 @@ func (c *Client) ImportModel(req *params.ImportModelRequest) error {
func (c *Client) UpdateMigratedModel(req *params.UpdateMigratedModelRequest) error {
return c.caller.APICall("JIMM", 3, "", "UpdateMigratedModel", req, nil)
}

// CrossModelQuery enables users to query all of their available models and each entity within the model.
//
// The query will run against output exactly like "juju status --format json", but for each of their models.
func (c *Client) CrossModelQuery(req *params.CrossModelQueryRequest) (*params.CrossModelQueryResponse, error) {
var response params.CrossModelQueryResponse
err := c.caller.APICall("JIMM", 4, "", "CrossModelQuery", req, &response)
return &response, err
}
16 changes: 16 additions & 0 deletions api/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,19 @@ type ImportModelRequest struct {
// ModelTag is the tag of the model that is to be imported.
ModelTag string `json:"model-tag"`
}

// CrossModelQueryRequest holds the parameters to perform a cross model query against
// JSON model statuses for every model this user has access to.
type CrossModelQueryRequest struct {
Type string `json:"type"`
Query string `json:"query"`
}

// CrossModelJqQueryResponse holds results for a cross-model query that has been filtered utilising JQ.
// It has two fields:
// - Results - A map of each iterated JQ output result. The key for this map is the model UUID.
// - Errors - A map of each iterated JQ *or* Status call error. The key for this map is the model UUID.
type CrossModelQueryResponse struct {
Results map[string][]any `json:"results"`
Errors map[string][]string `json:"errors"`
}
38 changes: 30 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/gorilla/websocket v1.5.0
github.com/gosuri/uitable v0.0.1
github.com/hashicorp/vault/api v1.8.2
github.com/itchyny/gojq v0.12.13
github.com/jackc/pgconn v1.7.0
github.com/jackc/pgx/v4 v4.9.0
github.com/juju/charm/v10 v10.0.0
Expand Down Expand Up @@ -57,6 +58,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork v1.0.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.24 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.18 // indirect
Expand All @@ -67,6 +69,7 @@ require (
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1 // indirect
github.com/Rican7/retry v0.3.1 // indirect
github.com/adrg/xdg v0.3.3 // indirect
github.com/armon/go-metrics v0.3.10 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.9.1 // indirect
Expand All @@ -91,6 +94,7 @@ require (
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/creack/pty v1.1.15 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/duo-labs/webauthn v0.0.0-20220815211337-00c9fb5711f5 // indirect
Expand All @@ -100,8 +104,11 @@ require (
github.com/fatih/color v1.13.0 // indirect
github.com/flosch/pongo2 v0.0.0-20200913210552-0d938eb266f3 // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fullstorydev/grpcurl v1.8.1 // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/gdamore/encoding v1.0.0 // indirect
github.com/gdamore/tcell/v2 v2.5.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/logr v1.2.2 // indirect
github.com/go-macaroon-bakery/macaroonpb v1.0.0 // indirect
Expand Down Expand Up @@ -148,6 +155,7 @@ require (
github.com/im7mortal/kmutex v1.0.1 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/itchyny/timefmt-go v0.1.5 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
Expand Down Expand Up @@ -197,6 +205,7 @@ require (
github.com/juju/usso v1.0.1 // indirect
github.com/juju/utils v0.0.0-20200604140309-9d78121a29e0 // indirect
github.com/juju/utils/v3 v3.0.2 // indirect
github.com/juju/viddy v0.0.0-beta5 // indirect
github.com/juju/webbrowser v1.0.0 // indirect
github.com/juju/worker/v3 v3.1.0 // indirect
github.com/julienschmidt/httprouter v1.3.0 // indirect
Expand All @@ -211,11 +220,13 @@ require (
github.com/lestrrat/go-jsval v0.0.0-20161012045717-b1258a10419f // indirect
github.com/lestrrat/go-pdebug v0.0.0-20160817063333-2e6eaaa5717f // indirect
github.com/lestrrat/go-structinfo v0.0.0-20160308131105-f74c056fe41f // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/lunixbochs/vtclean v1.0.0 // indirect
github.com/lxc/lxd v0.0.0-20220816180258-7e0418163fa9 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
Expand All @@ -225,6 +236,7 @@ require (
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/mittwald/vaultgo v0.1.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
Expand All @@ -234,23 +246,32 @@ require (
github.com/onsi/gomega v1.10.4 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/pierrec/lz4 v2.5.2+incompatible // indirect
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/sftp v1.13.5 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rivo/tview v0.0.0-20220610163003-691f46d6f500 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/rs/xid v1.4.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.12.0 // indirect
github.com/subosito/gotenv v1.4.0 // indirect
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 // indirect
github.com/urfave/cli v1.22.5 // indirect
github.com/vishvananda/netlink v1.2.1-beta.2 // indirect
Expand All @@ -260,10 +281,10 @@ require (
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
github.com/yohcop/openid-go v1.0.0 // indirect
go.etcd.io/bbolt v1.3.5 // indirect
go.etcd.io/etcd/api/v3 v3.5.0 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.0 // indirect
go.etcd.io/etcd/client/v2 v2.305.0 // indirect
go.etcd.io/etcd/client/v3 v3.5.0-alpha.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/v2 v2.305.4 // indirect
go.etcd.io/etcd/client/v3 v3.5.4 // indirect
go.etcd.io/etcd/etcdctl/v3 v3.5.0-alpha.0 // indirect
go.etcd.io/etcd/pkg/v3 v3.5.0-alpha.0 // indirect
go.etcd.io/etcd/raft/v3 v3.5.0-alpha.0 // indirect
Expand All @@ -276,7 +297,7 @@ require (
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.3.0 // indirect
Expand All @@ -290,6 +311,7 @@ require (
gopkg.in/gobwas/glob.v0 v0.2.3 // indirect
gopkg.in/httprequest.v1 v1.2.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/juju/environschema.v1 v1.0.1 // indirect
gopkg.in/macaroon-bakery.v3 v3.0.0 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect
Expand Down
Loading

0 comments on commit 46c42ea

Please sign in to comment.