Skip to content

Commit

Permalink
query: scope to tenant
Browse files Browse the repository at this point in the history
fixes: #304
fixes: #285
fixes: #286
  • Loading branch information
aastein authored Jul 24, 2018
1 parent 3ef2259 commit 6cde249
Show file tree
Hide file tree
Showing 20 changed files with 161 additions and 48 deletions.
6 changes: 3 additions & 3 deletions _integration/cmp/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ func orderQuery(daddr vars.Ref) gestalt.Component {
WithMeta(g.Require(daddr.Name()))
}

func leaseQuery(daddr vars.Ref) gestalt.Component {
func leaseQuery(key vars.Ref, daddr vars.Ref) gestalt.Component {
parse := js.Do(
js.Str(daddr.Var(), "items", "[0]", "id", "deployment"),
)

return akash("lease-query", "query", "lease").
return akash("lease-query", "query", "lease", "-k", key.Name()).
FN(parse).
WithMeta(g.Require(daddr.Name()))
}
Expand All @@ -73,7 +73,7 @@ func groupDeploy(key vars.Ref, daddr vars.Ref) gestalt.Component {
Run(g.Retry(5).
Run(orderQuery(daddr))).
Run(g.Retry(15).
Run(leaseQuery(daddr))).
Run(leaseQuery(key, daddr))).
Run(deployClose(key, daddr)).
WithMeta(g.Export(daddr.Name()))
}
12 changes: 10 additions & 2 deletions app/deployment/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (a *app) Query(state appstate.State, req tmtypes.RequestQuery) tmtypes.Resp

id := strings.TrimPrefix(req.Path, appstate.DeploymentPath)
if len(id) == 0 {
return a.doRangeQuery(state)
return a.doRangeQuery(state, req.Data)
}

key, err := keys.ParseDeploymentPath(id)
Expand Down Expand Up @@ -142,7 +142,7 @@ func (a *app) doQuery(state appstate.State, key keys.Deployment) tmtypes.Respons
}
}

func (a *app) doRangeQuery(state appstate.State) tmtypes.ResponseQuery {
func (a *app) doRangeQuery(state appstate.State, tenant []byte) tmtypes.ResponseQuery {
deps, err := state.Deployment().GetMaxRange()
if err != nil {
return tmtypes.ResponseQuery{
Expand All @@ -151,6 +151,14 @@ func (a *app) doRangeQuery(state appstate.State) tmtypes.ResponseQuery {
}
}

tenantDeps := []types.Deployment{}
for _, deployment := range deps.Items {
if bytes.Equal(deployment.Tenant, tenant) {
tenantDeps = append(tenantDeps, deployment)
}
}

deps.Items = tenantDeps
bytes, err := proto.Marshal(deps)
if err != nil {
return tmtypes.ResponseQuery{
Expand Down
18 changes: 15 additions & 3 deletions app/lease/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lease

import (
"bytes"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -83,7 +84,7 @@ func (a *app) Query(state appstate.State, req tmtypes.RequestQuery) tmtypes.Resp
id := strings.TrimPrefix(req.Path, appstate.LeasePath)

if len(id) == 0 {
return a.doRangeQuery(state)
return a.doRangeQuery(state, req.Data)
}

{
Expand Down Expand Up @@ -411,15 +412,26 @@ func (a *app) doQuery(state appstate.State, key keys.Lease) tmtypes.ResponseQuer
}
}

func (a *app) doRangeQuery(state appstate.State) tmtypes.ResponseQuery {
items, err := state.Lease().All()
func (a *app) doRangeQuery(state appstate.State, tenant []byte) tmtypes.ResponseQuery {
leases, err := state.Lease().All()
if err != nil {
return tmtypes.ResponseQuery{
Code: code.ERROR,
Log: err.Error(),
}
}

items := []*types.Lease{}
for _, lease := range leases {
deployment, err := state.Deployment().Get(lease.Deployment)
if err != nil {
a.Log().Error("deployment doesn't exist for lease")
}
if bytes.Equal(deployment.Tenant, tenant) {
items = append(items, lease)
}
}

coll := &types.Leases{Items: items}

bytes, err := proto.Marshal(coll)
Expand Down
2 changes: 1 addition & 1 deletion app/market/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/market/mocks/engine.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/market/mocks/facilitator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions cmd/akash/query/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ func queryAccountCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "account [account ...]",
Short: "query account",
Args: cobra.ExactArgs(1),
RunE: session.WithSession(session.RequireNode(doQueryAccountCommand)),
}

session.AddFlagKeyOptional(cmd, cmd.Flags())
return cmd
}

func doQueryAccountCommand(session session.Session, cmd *cobra.Command, args []string) error {
if len(args) == 0 {
_, info, err := session.Signer()
if err != nil {
return err
}
if err := handleMessage(session.QueryClient().Account(session.Ctx(), info.PubKey.Address().Bytes())); err != nil {
return err
}
return nil
}
for _, arg := range args {
key, err := keys.ParseAccountPath(arg)
if err != nil {
Expand Down
11 changes: 9 additions & 2 deletions cmd/akash/query/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ func queryDeploymentCommand() *cobra.Command {
Short: "query deployment",
RunE: session.WithSession(session.RequireNode(doQueryDeploymentCommand)),
}

session.AddFlagKeyOptional(cmd, cmd.Flags())
return cmd
}

func doQueryDeploymentCommand(session session.Session, cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return handleMessage(session.QueryClient().Deployments(session.Ctx()))
_, info, err := session.Signer()
if err != nil {
return err
}
if err := handleMessage(session.QueryClient().TenantDeployments(session.Ctx(), info.PubKey.Address().Bytes())); err != nil {
return err
}
return nil
}
for _, arg := range args {
key, err := keys.ParseDeploymentPath(arg)
Expand Down
11 changes: 9 additions & 2 deletions cmd/akash/query/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ func queryLeaseCommand() *cobra.Command {
Short: "query lease",
RunE: session.WithSession(session.RequireNode(doQueryLeaseCommand)),
}

session.AddFlagKeyOptional(cmd, cmd.Flags())
return cmd
}

func doQueryLeaseCommand(session session.Session, cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return handleMessage(session.QueryClient().Leases(session.Ctx()))
_, info, err := session.Signer()
if err != nil {
return err
}
if err := handleMessage(session.QueryClient().TenantLeases(session.Ctx(), info.PubKey.Address().Bytes())); err != nil {
return err
}
return nil
}
for _, arg := range args {
key, err := keys.ParseLeasePath(arg)
Expand Down
4 changes: 4 additions & 0 deletions cmd/akash/session/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func AddFlagKey(cmd *cobra.Command, flags *pflag.FlagSet) {
cmd.MarkFlagRequired(flagKey)
}

func AddFlagKeyOptional(cmd *cobra.Command, flags *pflag.FlagSet) {
flags.StringP(flagKey, "k", "", "key name")
}

func AddFlagNonce(cmd *cobra.Command, flags *pflag.FlagSet) {
flags.Uint64(flagNonce, 0, "nonce (optional)")
}
Expand Down
2 changes: 1 addition & 1 deletion marketplace/mocks/handler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion provider/cluster/kube/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion provider/cluster/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion provider/cluster/mocks/cluster.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion provider/cluster/mocks/deployment.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion provider/cluster/mocks/reservation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion provider/manifest/mocks/handler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6cde249

Please sign in to comment.