Skip to content

Commit

Permalink
Improve admin API
Browse files Browse the repository at this point in the history
  • Loading branch information
immesys committed Aug 1, 2018
1 parent 37c91bd commit f2a6183
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 94 deletions.
23 changes: 12 additions & 11 deletions Gopkg.lock

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

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

//go:generate go-bindata -o templates.go -prefix ../manifest_templates ../manifest_templates/

const PackageVersion = "4.13.0"
const PackageVersion = "4.14.1"

func main() {
app := cli.NewApp()
Expand Down
54 changes: 48 additions & 6 deletions tools/admincliserver/adminapi/adminapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,19 @@ func (a *apiProvider) ManifestAdd(ctx context.Context, p *ManifestAddParams) (*M
},
}, nil
}
if p.Deviceid == "" {
return &ManifestAddResponse{
Stat: &Status{
Code: bte.InvalidParameter,
Msg: "Device ID may not be empty",
},
}, nil
}
metadata := make(map[string]string)
for _, kv := range p.Metadata {
metadata[kv.Key] = kv.Value
}
dev := &manifest.ManifestDevice{Descriptor: p.Deviceid, Metadata: metadata, Streams: make(map[string]*manifest.ManifestDeviceStream)}
success, err := manifest.UpsertManifestDeviceAtomically(ctx, a.ec, dev)
md, err := manifest.RetrieveManifestDevice(ctx, a.ec, p.Deviceid)
if err != nil {
return &ManifestAddResponse{
Stat: &Status{
Expand All @@ -166,15 +173,25 @@ func (a *apiProvider) ManifestAdd(ctx context.Context, p *ManifestAddParams) (*M
},
}, nil
}
if !success {
if md != nil {
return &ManifestAddResponse{
Stat: &Status{
Code: bte.ManifestDeviceDuplicated,
Msg: err.Error(),
},
}, nil
}
return &ManifestAddResponse{}, nil
dev := &manifest.ManifestDevice{Descriptor: p.Deviceid, Metadata: metadata, Streams: make(map[string]*manifest.ManifestDeviceStream)}
err = manifest.UpsertManifestDevice(ctx, a.ec, dev)
if err != nil {
return &ManifestAddResponse{
Stat: &Status{
Code: bte.ManifestError,
Msg: err.Error(),
},
}, nil
}
return &ManifestAddResponse{Deviceid: p.Deviceid}, nil
}

func (a *apiProvider) ManifestDel(ctx context.Context, p *ManifestDelParams) (*ManifestDelResponse, error) {
Expand All @@ -187,7 +204,7 @@ func (a *apiProvider) ManifestDel(ctx context.Context, p *ManifestDelParams) (*M
},
}, nil
}
err := manifest.DeleteManifestDevice(ctx, a.ec, p.Deviceid)
md, err := manifest.RetrieveManifestDevice(ctx, a.ec, p.Deviceid)
if err != nil {
return &ManifestDelResponse{
Stat: &Status{
Expand All @@ -196,7 +213,24 @@ func (a *apiProvider) ManifestDel(ctx context.Context, p *ManifestDelParams) (*M
},
}, nil
}
return &ManifestDelResponse{}, nil
if md == nil {
return &ManifestDelResponse{
Stat: &Status{
Code: bte.ManifestDeviceDoesntExist,
Msg: "No device exists with that deviceid",
},
}, nil
}
err = manifest.DeleteManifestDevice(ctx, a.ec, p.Deviceid)
if err != nil {
return &ManifestDelResponse{
Stat: &Status{
Code: bte.ManifestError,
Msg: err.Error(),
},
}, nil
}
return &ManifestDelResponse{Deviceid: p.Deviceid}, nil
}

func (a *apiProvider) ManifestDelPrefix(ctx context.Context, p *ManifestDelPrefixParams) (*ManifestDelPrefixResponse, error) {
Expand All @@ -218,6 +252,14 @@ func (a *apiProvider) ManifestDelPrefix(ctx context.Context, p *ManifestDelPrefi
},
}, nil
}
if n == 0 {
return &ManifestDelPrefixResponse{
Stat: &Status{
Code: bte.ManifestDeviceDoesntExist,
Msg: "No devices exist with this device id pattern",
},
}, nil
}
return &ManifestDelPrefixResponse{
Numdeleted: uint32(n),
}, nil
Expand Down
Loading

0 comments on commit f2a6183

Please sign in to comment.