Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1489 from kindermoumoute/refactor_API
Browse files Browse the repository at this point in the history
Refactor api and add v2 API (beta)
  • Loading branch information
jcooklin authored Jan 26, 2017
2 parents da6ad2e + e741f41 commit 8080135
Show file tree
Hide file tree
Showing 55 changed files with 3,991 additions and 1,426 deletions.
2 changes: 1 addition & 1 deletion cmd/snaptel/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"time"

"github.com/intelsdi-x/snap/mgmt/rest/client"
"github.com/intelsdi-x/snap/mgmt/rest/rbody"
"github.com/intelsdi-x/snap/mgmt/rest/v1/rbody"
"github.com/urfave/cli"

"github.com/intelsdi-x/snap/pkg/stringutils"
Expand Down
16 changes: 9 additions & 7 deletions control/plugin/cpolicy/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,18 @@ func (p *ConfigPolicyNode) Add(rules ...Rule) {
}
}

type RuleTableSlice []RuleTable

type RuleTable struct {
Name string
Type string
Default interface{}
Required bool
Minimum interface{}
Maximum interface{}
Name string `json:"name"`
Type string `json:"type"`
Default interface{} `json:"default,omitempty"`
Required bool `json:"required"`
Minimum interface{} `json:"minimum,omitempty"`
Maximum interface{} `json:"maximum,omitempty"`
}

func (p *ConfigPolicyNode) RulesAsTable() []RuleTable {
func (p *ConfigPolicyNode) RulesAsTable() RuleTableSlice {
p.mutex.Lock()
defer p.mutex.Unlock()

Expand Down
18 changes: 18 additions & 0 deletions mgmt/rest/api/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package api

import (
"github.com/julienschmidt/httprouter"
)

type API interface {
GetRoutes() []Route
BindMetricManager(Metrics)
BindTaskManager(Tasks)
BindTribeManager(Tribe)
BindConfigManager(Config)
}

type Route struct {
Method, Path string
Handle httprouter.Handle
}
15 changes: 15 additions & 0 deletions mgmt/rest/api/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package api

import (
"github.com/intelsdi-x/snap/core"
"github.com/intelsdi-x/snap/core/cdata"
)

type Config interface {
GetPluginConfigDataNode(core.PluginType, string, int) cdata.ConfigDataNode
GetPluginConfigDataNodeAll() cdata.ConfigDataNode
MergePluginConfigDataNode(pluginType core.PluginType, name string, ver int, cdn *cdata.ConfigDataNode) cdata.ConfigDataNode
MergePluginConfigDataNodeAll(cdn *cdata.ConfigDataNode) cdata.ConfigDataNode
DeletePluginConfigDataNodeField(pluginType core.PluginType, name string, ver int, fields ...string) cdata.ConfigDataNode
DeletePluginConfigDataNodeFieldAll(fields ...string) cdata.ConfigDataNode
}
18 changes: 18 additions & 0 deletions mgmt/rest/api/metric.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package api

import (
"github.com/intelsdi-x/snap/core"
"github.com/intelsdi-x/snap/core/serror"
)

type Metrics interface {
MetricCatalog() ([]core.CatalogedMetric, error)
FetchMetrics(core.Namespace, int) ([]core.CatalogedMetric, error)
GetMetricVersions(core.Namespace) ([]core.CatalogedMetric, error)
GetMetric(core.Namespace, int) (core.CatalogedMetric, error)
Load(*core.RequestedPlugin) (core.CatalogedPlugin, serror.SnapError)
Unload(core.Plugin) (core.CatalogedPlugin, serror.SnapError)
PluginCatalog() core.PluginCatalog
AvailablePlugins() []core.AvailablePlugin
GetAutodiscoverPaths() []string
}
19 changes: 19 additions & 0 deletions mgmt/rest/api/task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package api

import (
"github.com/intelsdi-x/snap/core"
"github.com/intelsdi-x/snap/core/serror"
"github.com/intelsdi-x/snap/pkg/schedule"
"github.com/intelsdi-x/snap/scheduler/wmap"
)

type Tasks interface {
CreateTask(schedule.Schedule, *wmap.WorkflowMap, bool, ...core.TaskOption) (core.Task, core.TaskErrors)
GetTasks() map[string]core.Task
GetTask(string) (core.Task, error)
StartTask(string) []serror.SnapError
StopTask(string) []serror.SnapError
RemoveTask(string) error
WatchTask(string, core.TaskWatcherHandler) (core.TaskWatcherCloser, error)
EnableTask(string) (core.Task, error)
}
17 changes: 17 additions & 0 deletions mgmt/rest/api/tribe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package api

import (
"github.com/intelsdi-x/snap/core/serror"
"github.com/intelsdi-x/snap/mgmt/tribe/agreement"
)

type Tribe interface {
GetAgreement(name string) (*agreement.Agreement, serror.SnapError)
GetAgreements() map[string]*agreement.Agreement
AddAgreement(name string) serror.SnapError
RemoveAgreement(name string) serror.SnapError
JoinAgreement(agreementName, memberName string) serror.SnapError
LeaveAgreement(agreementName, memberName string) serror.SnapError
GetMembers() []string
GetMember(name string) *agreement.Member
}
2 changes: 1 addition & 1 deletion mgmt/rest/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (

"github.com/asaskevich/govalidator"

"github.com/intelsdi-x/snap/mgmt/rest/rbody"
"github.com/intelsdi-x/snap/mgmt/rest/v1/rbody"
)

var (
Expand Down
7 changes: 4 additions & 3 deletions mgmt/rest/client/client_func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (

"github.com/intelsdi-x/snap/control"
"github.com/intelsdi-x/snap/mgmt/rest"
"github.com/intelsdi-x/snap/mgmt/rest/v1"
"github.com/intelsdi-x/snap/plugin/helper"
"github.com/intelsdi-x/snap/scheduler"
"github.com/intelsdi-x/snap/scheduler/wmap"
Expand Down Expand Up @@ -75,7 +76,7 @@ func getWMFromSample(sample string) *wmap.WorkflowMap {
// When we eventually have a REST API Stop command this can be killed.
func startAPI() string {
// Start a REST API to talk to
rest.StreamingBufferWindow = 0.01
v1.StreamingBufferWindow = 0.01
log.SetLevel(LOG_LEVEL)
r, _ := rest.New(rest.GetDefaultConfig())
c := control.New(control.GetDefaultConfig())
Expand Down Expand Up @@ -490,7 +491,7 @@ func TestSnapClient(t *testing.T) {
})
Convey("WatchTasks", func() {
Convey("invalid task ID", func() {
rest.StreamingBufferWindow = 0.01
v1.StreamingBufferWindow = 0.01

type ea struct {
events []string
Expand Down Expand Up @@ -521,7 +522,7 @@ func TestSnapClient(t *testing.T) {
So(r.Err.Error(), ShouldEqual, "Task not found: ID(1)")
})
Convey("event stream", func() {
rest.StreamingBufferWindow = 0.01
v1.StreamingBufferWindow = 0.01
sch := &Schedule{Type: "simple", Interval: "100ms"}
tf := c.CreateTask(sch, wf, "baron", "", false, 0)

Expand Down
2 changes: 1 addition & 1 deletion mgmt/rest/client/client_tribe_func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/intelsdi-x/snap/control"
"github.com/intelsdi-x/snap/mgmt/rest"
"github.com/intelsdi-x/snap/mgmt/rest/client"
"github.com/intelsdi-x/snap/mgmt/rest/rbody"
"github.com/intelsdi-x/snap/mgmt/rest/v1/rbody"
"github.com/intelsdi-x/snap/mgmt/tribe"
"github.com/intelsdi-x/snap/scheduler"
)
Expand Down
2 changes: 1 addition & 1 deletion mgmt/rest/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"net/url"

"github.com/intelsdi-x/snap/core/ctypes"
"github.com/intelsdi-x/snap/mgmt/rest/rbody"
"github.com/intelsdi-x/snap/mgmt/rest/v1/rbody"
)

// GetPluginConfig retrieves the merged plugin config given the type of plugin,
Expand Down
2 changes: 1 addition & 1 deletion mgmt/rest/client/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"errors"
"fmt"

"github.com/intelsdi-x/snap/mgmt/rest/rbody"
"github.com/intelsdi-x/snap/mgmt/rest/v1/rbody"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion mgmt/rest/client/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"time"

"github.com/intelsdi-x/snap/core/serror"
"github.com/intelsdi-x/snap/mgmt/rest/rbody"
"github.com/intelsdi-x/snap/mgmt/rest/v1/rbody"
)

// LoadPlugin loads plugins for the given plugin names.
Expand Down
2 changes: 1 addition & 1 deletion mgmt/rest/client/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"time"

"github.com/intelsdi-x/snap/core"
"github.com/intelsdi-x/snap/mgmt/rest/rbody"
"github.com/intelsdi-x/snap/mgmt/rest/v1/rbody"
"github.com/intelsdi-x/snap/scheduler/wmap"
)

Expand Down
2 changes: 1 addition & 1 deletion mgmt/rest/client/tribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"encoding/json"
"fmt"

"github.com/intelsdi-x/snap/mgmt/rest/rbody"
"github.com/intelsdi-x/snap/mgmt/rest/v1/rbody"
)

// ListMembers retrieves a list of tribe members through an HTTP GET call.
Expand Down
Loading

0 comments on commit 8080135

Please sign in to comment.