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

Commit

Permalink
Adds tribe plugin agreements
Browse files Browse the repository at this point in the history
JRA-225 #close added flags enabling tribe
JRA-226
  • Loading branch information
jcooklin committed Oct 1, 2015
1 parent b894893 commit 04502bb
Show file tree
Hide file tree
Showing 21 changed files with 1,431 additions and 146 deletions.
4 changes: 4 additions & 0 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ func (p *pluginControl) Name() string {
return "control"
}

func (p *pluginControl) RegisterEventHandler(name string, h gomit.Handler) error {
return p.eventManager.RegisterHandler("tribe", h)
}

// Begin handling load, unload, and inventory
func (p *pluginControl) Start() error {
// Start pluginManager when pluginControl starts
Expand Down
4 changes: 4 additions & 0 deletions control/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ func (lp *loadedPlugin) Name() string {
return lp.Meta.Name
}

func (lp *loadedPlugin) PluginPath() string {
return lp.Path
}

func (l *loadedPlugin) Key() string {
return fmt.Sprintf("%s:%s:%d", l.TypeName(), l.Name(), l.Version())
}
Expand Down
4 changes: 3 additions & 1 deletion core/perror/perror.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ type PulseError interface {
SetFields(map[string]interface{})
}

type Fields map[string]interface{}

type pulseError struct {
err error
fields map[string]interface{}
fields Fields
}

// New returns an initialized PulseError.
Expand Down
1 change: 1 addition & 0 deletions core/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type CatalogedPlugin interface {
Plugin
IsSigned() bool
Status() string
PluginPath() string
LoadedTimestamp() *time.Time
}

Expand Down
2 changes: 1 addition & 1 deletion mgmt/rest/client/client_func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func startAPI(port int) string {
r.BindMetricManager(c)
r.BindTaskManager(s)
r.Start(":" + fmt.Sprint(port))
time.Sleep(time.Millisecond * 100)
time.Sleep(100 * time.Millisecond)
return fmt.Sprintf("http://localhost:%d", port)
}

Expand Down
4 changes: 2 additions & 2 deletions mgmt/rest/client/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func (c *Client) GetPlugins(details bool) *GetPluginsResult {

switch resp.Meta.Type {
// TODO change this to concrete const type when Joel adds it
case rbody.PluginListReturnedType:
case rbody.PluginListType:
// Success
b := resp.Body.(*rbody.PluginListReturned)
b := resp.Body.(*rbody.PluginList)
r.LoadedPlugins = convertLoadedPlugins(b.LoadedPlugins)
r.AvailablePlugins = convertAvailablePlugins(b.AvailablePlugins)
return r
Expand Down
70 changes: 68 additions & 2 deletions mgmt/rest/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

var (
ErrMissingPluginName = errors.New("missing plugin name")
ErrPluginNotFound = errors.New("plugin not found")
)

type plugin struct {
Expand Down Expand Up @@ -200,7 +201,7 @@ func (s *Server) getPlugins(w http.ResponseWriter, r *http.Request, _ httprouter
}
}

plugins := new(rbody.PluginListReturned)
plugins := new(rbody.PluginList)

// Cache the catalog here to avoid multiple reads
plCatalog := s.mm.PluginCatalog()
Expand Down Expand Up @@ -244,5 +245,70 @@ func (s *Server) getPluginsByType(w http.ResponseWriter, r *http.Request, params
func (s *Server) getPluginsByName(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
}

func (s *Server) getPlugin(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
func (s *Server) getPlugin(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
plName := p.ByName("name")
plType := p.ByName("type")
plVersion, iErr := strconv.ParseInt(p.ByName("version"), 10, 0)
f := map[string]interface{}{
"plugin-name": plName,
"plugin-version": plVersion,
"plugin-type": plType,
}

if iErr != nil {
pe := perror.New(errors.New("invalid version"))
pe.SetFields(f)
respond(400, rbody.FromPulseError(pe), w)
return
}

if plName == "" {
pe := perror.New(errors.New("missing plugin name"))
pe.SetFields(f)
respond(400, rbody.FromPulseError(pe), w)
return
}
if plType == "" {
pe := perror.New(errors.New("missing plugin type"))
pe.SetFields(f)
respond(400, rbody.FromPulseError(pe), w)
return
}

pluginCatalog := s.mm.PluginCatalog()
var plugin core.CatalogedPlugin
for _, item := range pluginCatalog {
if item.Name() == plName &&
item.Version() == int(plVersion) &&
item.TypeName() == plType {
plugin = item
break
}
}
if plugin == nil {
pe := perror.New(ErrPluginNotFound, f)
respond(404, rbody.FromPulseError(pe), w)
return
}

b, err := ioutil.ReadFile(plugin.PluginPath())
if err != nil {
f["plugin-path"] = plugin.PluginPath()
pe := perror.New(err, f)
respond(500, rbody.FromPulseError(pe), w)
return
}

w.Header().Set("Content-Encoding", "gzip")
gz := gzip.NewWriter(w)
defer gz.Close()
_, err = gz.Write(b)
if err != nil {
f["plugin-path"] = plugin.PluginPath()
pe := perror.New(err, f)
respond(500, rbody.FromPulseError(pe), w)
return
}

// w.WriteHeader(200)
}
16 changes: 14 additions & 2 deletions mgmt/rest/rbody/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ var (

func UnmarshalBody(t string, b []byte) (Body, error) {
switch t {
case PluginListReturnedType:
return unmarshalAndHandleError(b, &PluginListReturned{})
case PluginListType:
return unmarshalAndHandleError(b, &PluginList{})
case PluginsLoadedType:
return unmarshalAndHandleError(b, &PluginsLoaded{})
case PluginUnloadedType:
Expand All @@ -44,6 +44,18 @@ func UnmarshalBody(t string, b []byte) (Body, error) {
return unmarshalAndHandleError(b, &MetricsReturned{})
case ScheduledTaskWatchingEndedType:
return unmarshalAndHandleError(b, &ScheduledTaskWatchingEnded{})
case TribeMemberListType:
return unmarshalAndHandleError(b, &TribeMemberList{})
case TribeAgreementListType:
return unmarshalAndHandleError(b, &TribeAgreementList{})
case TribeAddAgreementType:
return unmarshalAndHandleError(b, &TribeAddAgreement{})
case TribeMemberShowType:
return unmarshalAndHandleError(b, &TribeMemberShow{})
case TribeJoinAgreementType:
return unmarshalAndHandleError(b, &TribeJoinAgreement{})
case TribeGetAgreementType:
return unmarshalAndHandleError(b, &TribeGetAgreement{})
case ErrorType:
return unmarshalAndHandleError(b, &Error{})
default:
Expand Down
14 changes: 7 additions & 7 deletions mgmt/rest/rbody/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
)

const (
PluginsLoadedType = "plugins_loaded"
PluginUnloadedType = "plugin_unloaded"
PluginListReturnedType = "plugin_list_returned"
PluginsLoadedType = "plugins_loaded"
PluginUnloadedType = "plugin_unloaded"
PluginListType = "plugin_list_returned"
)

// Successful response to the loading of a plugins
Expand Down Expand Up @@ -45,17 +45,17 @@ func (u *PluginUnloaded) ResponseBodyType() string {
return PluginUnloadedType
}

type PluginListReturned struct {
type PluginList struct {
LoadedPlugins []LoadedPlugin `json:"loaded_plugins,omitempty"`
AvailablePlugins []AvailablePlugin `json:"available_plugins,omitempty"`
}

func (p *PluginListReturned) ResponseBodyMessage() string {
func (p *PluginList) ResponseBodyMessage() string {
return "Plugin list returned"
}

func (p *PluginListReturned) ResponseBodyType() string {
return PluginListReturnedType
func (p *PluginList) ResponseBodyType() string {
return PluginListType
}

type LoadedPlugin struct {
Expand Down
88 changes: 88 additions & 0 deletions mgmt/rest/rbody/tribe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package rbody

import "github.com/intelsdi-x/pulse/mgmt/tribe"

const (
TribeAgreementListType = "tribe_agreement_list_returned"
TribeGetAgreementType = "tribe_agreement_returned"
TribeAddAgreementType = "tribe_agreement_created"
TribeAddMemberType = "tribe_member_added"
TribeJoinAgreementType = "tribe_agreement_joined"
TribeMemberListType = "tribe_member_list_returned"
TribeMemberShowType = "tribe_member_details_returned"
)

type TribeAddAgreement struct {
Name string
}

func (t *TribeAddAgreement) ResponseBodyMessage() string {
return "Tribe agreement created"
}

func (t *TribeAddAgreement) ResponseBodyType() string {
return TribeAddAgreementType
}

type TribeGetAgreement struct {
Agreement *tribe.Agreement `json:"agreement"`
}

func (t *TribeGetAgreement) ResponseBodyMessage() string {
return "Tribe agreement returned"
}

func (t *TribeGetAgreement) ResponseBodyType() string {
return TribeGetAgreementType
}

type TribeAgreementList struct {
Agreements map[string]*tribe.Agreement `json:"agreements"`
}

func (t *TribeAgreementList) ResponseBodyMessage() string {
return "Tribe agreements retrieved"
}

func (t *TribeAgreementList) ResponseBodyType() string {
return TribeAgreementListType
}

type TribeJoinAgreement struct {
Agreement *tribe.Agreement `json:"agreement"`
}

func (t *TribeJoinAgreement) ResponseBodyMessage() string {
return "Tribe agreement joined"
}

func (t *TribeJoinAgreement) ResponseBodyType() string {
return TribeJoinAgreementType
}

type TribeMemberList struct {
Members []string `json:"members"`
}

func (t *TribeMemberList) ResponseBodyMessage() string {
return "Tribe members retrieved"
}

func (t *TribeMemberList) ResponseBodyType() string {
return TribeMemberListType
}

type TribeMemberShow struct {
Name string `json:"name"`
PluginAgreement string `json:"plugin_agreement"`
Tags map[string]string `json:"tags"`
TaskAgreements []string `json:"task_agreements"`
}

func (t *TribeMemberShow) ResponseBodyMessage() string {
return "Tribe member details retrieved"
}

func (t *TribeMemberShow) ResponseBodyType() string {
return TribeMemberShowType
}
Loading

0 comments on commit 04502bb

Please sign in to comment.