Skip to content

Commit e6f16aa

Browse files
authored
Tenant sends manifest to provider over http
fixes: #186
1 parent 112934a commit e6f16aa

File tree

21 files changed

+610
-132
lines changed

21 files changed

+610
-132
lines changed

_docs/attributes.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
- name: region
2-
value: us-west
3-
- name: tier
4-
value: "5"
1+
hostURI: http://localhost:3001/manifest
2+
attributes:
3+
- name: region
4+
value: us-west
5+
- name: tier
6+
value: "5"

_docs/manifest.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
image: path/to/docker

_integration/attributes.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
- name: region
2-
value: us-west
3-
- name: tier
4-
value: "5"
1+
hostURI: http://localhost:3001/manifest
2+
attributes:
3+
- name: region
4+
value: us-west
5+
- name: tier
6+
value: "5"

app/provider/app.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provider
33
import (
44
"bytes"
55
"fmt"
6+
"net/url"
67
"strings"
78

89
"github.com/gogo/protobuf/proto"
@@ -171,6 +172,13 @@ func (a *app) doCheckTx(ctx apptypes.Context, tx *types.TxCreateProvider) tmtype
171172
return tmtypes.ResponseCheckTx{Code: code.INVALID_TRANSACTION, Log: "invalid nonce"}
172173
}
173174

175+
if _, err := url.Parse(tx.HostURI); err != nil {
176+
return tmtypes.ResponseCheckTx{
177+
Code: code.INVALID_TRANSACTION,
178+
Log: "invalid network address",
179+
}
180+
}
181+
174182
return tmtypes.ResponseCheckTx{}
175183
}
176184

@@ -187,6 +195,7 @@ func (a *app) doDeliverTx(ctx apptypes.Context, tx *types.TxCreateProvider) tmty
187195
provider := &types.Provider{
188196
Address: state.ProviderAddress(tx.Owner, tx.Nonce),
189197
Owner: tx.Owner,
198+
HostURI: tx.HostURI,
190199
Attributes: tx.Attributes,
191200
}
192201

cmd/akash/context/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ func (ctx *context) Key() (keys.Info, error) {
173173
if err != nil {
174174
return keys.Info{}, err
175175
}
176+
176177
return info, nil
177178
}
178179

cmd/akash/deployment.go

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
"os"
88

99
"github.com/ovrclk/akash/cmd/akash/context"
10+
"github.com/ovrclk/akash/cmd/akash/query"
1011
"github.com/ovrclk/akash/cmd/common"
12+
"github.com/ovrclk/akash/manifest"
1113
"github.com/ovrclk/akash/marketplace"
1214
"github.com/ovrclk/akash/state"
1315
"github.com/ovrclk/akash/testutil"
@@ -27,16 +29,17 @@ func deploymentCommand() *cobra.Command {
2729

2830
cmd.AddCommand(createDeploymentCommand())
2931
cmd.AddCommand(closeDeploymentCommand())
32+
cmd.AddCommand(sendManifestCommand())
3033

3134
return cmd
3235
}
3336

3437
func createDeploymentCommand() *cobra.Command {
3538

3639
cmd := &cobra.Command{
37-
Use: "create <file>",
40+
Use: "create <deployment file> [manifest]",
3841
Short: "create a deployment",
39-
Args: cobra.ExactArgs(1),
42+
Args: cobra.RangeArgs(1, 2),
4043
RunE: context.WithContext(
4144
context.RequireKey(context.RequireNode(createDeployment))),
4245
}
@@ -50,8 +53,7 @@ func createDeploymentCommand() *cobra.Command {
5053
}
5154

5255
func parseDeployment(file string, nonce uint64) ([]*types.GroupSpec, int64, error) {
53-
// todo: read and parse deployment yaml file
54-
56+
// XXX: read and parse deployment yaml file
5557
specs := []*types.GroupSpec{}
5658

5759
/* begin stub data */
@@ -66,7 +68,6 @@ func parseDeployment(file string, nonce uint64) ([]*types.GroupSpec, int64, erro
6668
}
6769

6870
ttl := int64(5)
69-
7071
/* end stub data */
7172

7273
return specs, ttl, nil
@@ -88,6 +89,14 @@ func createDeployment(ctx context.Context, cmd *cobra.Command, args []string) er
8889
return err
8990
}
9091

92+
mani := &manifest.Manifest{}
93+
if len(args) > 1 {
94+
err = mani.Parse(args[1])
95+
if err != nil {
96+
return err
97+
}
98+
}
99+
91100
tx, err := txutil.BuildTx(signer, nonce, &types.TxCreateDeployment{
92101
Tenant: key.Address(),
93102
Nonce: nonce,
@@ -130,6 +139,19 @@ func createDeployment(ctx context.Context, cmd *cobra.Command, args []string) er
130139
if bytes.Equal(tx.Deployment, address) {
131140
fmt.Printf("Group %v/%v Lease: %v\n", tx.Group, len(groups),
132141
X(state.FulfillmentID(tx.Deployment, tx.Group, tx.Order, tx.Provider)))
142+
// get lease provider
143+
prov, err := query.Provider(ctx, &tx.Provider)
144+
if err != nil {
145+
fmt.Printf("ERROR: %v", err)
146+
}
147+
148+
lease := state.LeaseID(tx.Deployment, tx.Group, tx.Order, tx.Provider)
149+
// send manifest over http to provider uri
150+
fmt.Printf("Sending manifest to %v...\n", prov.HostURI)
151+
err = mani.Send(signer, prov.Address, lease, prov.HostURI)
152+
if err != nil {
153+
fmt.Printf("ERROR: %v", err)
154+
}
133155
expected--
134156
}
135157
if expected == 0 {
@@ -201,3 +223,49 @@ func closeDeployment(ctx context.Context, cmd *cobra.Command, args []string) err
201223
fmt.Println("Closing deployment")
202224
return nil
203225
}
226+
227+
func sendManifestCommand() *cobra.Command {
228+
229+
cmd := &cobra.Command{
230+
Use: "sendmani [manifest] [lease]",
231+
Short: "send manifest to lease provider",
232+
Args: cobra.ExactArgs(2),
233+
RunE: context.WithContext(
234+
context.RequireKey(context.RequireNode(sendManifest))),
235+
}
236+
237+
context.AddFlagNode(cmd, cmd.Flags())
238+
context.AddFlagKey(cmd, cmd.Flags())
239+
240+
return cmd
241+
}
242+
243+
func sendManifest(ctx context.Context, cmd *cobra.Command, args []string) error {
244+
signer, _, err := ctx.Signer()
245+
if err != nil {
246+
return err
247+
}
248+
249+
mani := &manifest.Manifest{}
250+
err = mani.Parse(args[0])
251+
if err != nil {
252+
return err
253+
}
254+
255+
leaseAddr := base.Bytes(args[1])
256+
lease, err := query.Lease(ctx, &leaseAddr)
257+
if err != nil {
258+
return err
259+
}
260+
261+
provider, err := query.Provider(ctx, &lease.Provider)
262+
if err != nil {
263+
return err
264+
}
265+
266+
err = mani.Send(signer, lease.Provider, leaseAddr, provider.HostURI)
267+
if err != nil {
268+
return err
269+
}
270+
return nil
271+
}

cmd/akash/provider.go

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7-
"io/ioutil"
87
"math/rand"
98
"strconv"
109

1110
"github.com/ovrclk/akash/cmd/akash/constants"
1211
"github.com/ovrclk/akash/cmd/akash/context"
1312
"github.com/ovrclk/akash/cmd/akash/query"
1413
"github.com/ovrclk/akash/cmd/common"
14+
"github.com/ovrclk/akash/manifest"
1515
"github.com/ovrclk/akash/marketplace"
1616
qp "github.com/ovrclk/akash/query"
1717
"github.com/ovrclk/akash/state"
1818
"github.com/ovrclk/akash/txutil"
1919
"github.com/ovrclk/akash/types"
2020
"github.com/ovrclk/akash/types/base"
21+
"github.com/ovrclk/akash/types/provider"
2122
. "github.com/ovrclk/akash/util"
2223
"github.com/spf13/cobra"
23-
"gopkg.in/yaml.v2"
2424
)
2525

2626
func providerCommand() *cobra.Command {
@@ -39,14 +39,15 @@ func providerCommand() *cobra.Command {
3939
cmd.AddCommand(runCommand())
4040
cmd.AddCommand(closeFulfillmentCommand())
4141
cmd.AddCommand(closeLeaseCommand())
42+
cmd.AddCommand(runManifestServerCommand())
4243

4344
return cmd
4445
}
4546

4647
func createProviderCommand() *cobra.Command {
4748

4849
cmd := &cobra.Command{
49-
Use: "create [file] [flags]",
50+
Use: "create <file>",
5051
Short: "create a provider",
5152
Args: cobra.ExactArgs(1),
5253
RunE: context.WithContext(context.RequireNode(doCreateProviderCommand)),
@@ -95,14 +96,16 @@ func doCreateProviderCommand(ctx context.Context, cmd *cobra.Command, args []str
9596
return err
9697
}
9798

98-
attributes, err := parseProvider(args[0], nonce)
99+
prov := &provider.Provider{}
100+
err = prov.Parse(args[0])
99101
if err != nil {
100102
return err
101103
}
102104

103105
tx, err := txutil.BuildTx(signer, nonce, &types.TxCreateProvider{
104106
Owner: key.Address(),
105-
Attributes: *attributes,
107+
HostURI: prov.HostURI,
108+
Attributes: prov.Attributes,
106109
Nonce: nonce,
107110
})
108111
if err != nil {
@@ -127,22 +130,6 @@ func doCreateProviderCommand(ctx context.Context, cmd *cobra.Command, args []str
127130
return nil
128131
}
129132

130-
func parseProvider(file string, nonce uint64) (*[]types.ProviderAttribute, error) {
131-
132-
contents, err := ioutil.ReadFile(file)
133-
if err != nil {
134-
return nil, err
135-
}
136-
137-
attributes := &[]types.ProviderAttribute{}
138-
err = yaml.Unmarshal([]byte(contents), attributes)
139-
if err != nil {
140-
return nil, err
141-
}
142-
143-
return attributes, nil
144-
}
145-
146133
func runCommand() *cobra.Command {
147134
cmd := &cobra.Command{
148135
Use: "run <provider>",
@@ -376,3 +363,33 @@ func doCloseLeaseCommand(ctx context.Context, cmd *cobra.Command, args []string)
376363

377364
return nil
378365
}
366+
367+
func runManifestServerCommand() *cobra.Command {
368+
369+
cmd := &cobra.Command{
370+
Use: "servmani [port] [loglevel = (debug|info|warn|error|fatal|panic)]",
371+
Short: "receive deployment manifest",
372+
Args: cobra.RangeArgs(0, 2),
373+
RunE: context.WithContext(context.RequireNode(doRunManifestServerCommand)),
374+
}
375+
376+
context.AddFlagKeyType(cmd, cmd.Flags())
377+
378+
return cmd
379+
}
380+
381+
func doRunManifestServerCommand(ctx context.Context, cmd *cobra.Command, args []string) error {
382+
383+
port := "3001"
384+
if len(args) == 1 {
385+
port = args[0]
386+
}
387+
388+
loglevel := "debug"
389+
if len(args) == 2 {
390+
loglevel = args[1]
391+
}
392+
393+
manifest.RunServ(port, loglevel)
394+
return nil
395+
}

cmd/akash/query/lease.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,16 @@ func LeasesForDeployment(ctx context.Context, deployment *base.Bytes) (*types.Le
4545
}
4646
return leases, nil
4747
}
48+
49+
func Lease(ctx context.Context, leaseAddr *base.Bytes) (*types.Lease, error) {
50+
lease := &types.Lease{}
51+
path := state.LeasePath + util.X(*leaseAddr)
52+
result, err := Query(ctx, path)
53+
if err != nil {
54+
return nil, err
55+
}
56+
if err := proto.Unmarshal(result.Response.Value, lease); err != nil {
57+
return nil, err
58+
}
59+
return lease, nil
60+
}

cmd/akash/query/provider.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package query
22

33
import (
4+
"github.com/gogo/protobuf/proto"
45
"github.com/ovrclk/akash/cmd/akash/context"
56
"github.com/ovrclk/akash/state"
67
"github.com/ovrclk/akash/types"
8+
"github.com/ovrclk/akash/types/base"
9+
"github.com/ovrclk/akash/util"
710
"github.com/spf13/cobra"
811
)
912

@@ -29,3 +32,16 @@ func doQueryProviderCommand(ctx context.Context, cmd *cobra.Command, args []stri
2932
return doQuery(ctx, path, structure)
3033
}
3134
}
35+
36+
func Provider(ctx context.Context, paddr *base.Bytes) (*types.Provider, error) {
37+
provider := &types.Provider{}
38+
path := state.ProviderPath + util.X(*paddr)
39+
result, err := Query(ctx, path)
40+
if err != nil {
41+
return nil, err
42+
}
43+
if err := proto.Unmarshal(result.Response.Value, provider); err != nil {
44+
return nil, err
45+
}
46+
return provider, nil
47+
}

glide.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)