From 90399efb0a11cc07357361078b2549491756c7ad Mon Sep 17 00:00:00 2001 From: Tiffany Jernigan Date: Mon, 30 Nov 2015 00:02:37 -0800 Subject: [PATCH] perror -> serror --- control/available_plugin.go | 20 +- control/control.go | 228 ++++++++++---------- control/control_test.go | 30 +-- control/metrics.go | 30 +-- control/mttrie.go | 22 +- control/plugin/client/httpjsonrpc_test.go | 12 +- control/plugin_manager.go | 46 ++-- control/plugin_manager_test.go | 6 +- core/{perror/perror.go => serror/serror.go} | 2 +- core/task.go | 4 +- mgmt/rest/client/plugin.go | 10 +- mgmt/rest/plugin.go | 58 ++--- mgmt/rest/rbody/error.go | 6 +- mgmt/rest/server.go | 20 +- mgmt/rest/tribe.go | 64 +++--- mgmt/tribe/tribe.go | 58 ++--- mgmt/tribe/tribe_test.go | 14 +- mgmt/tribe/worker/worker.go | 10 +- mgmt/tribe/worker/worker_test.go | 6 +- scheduler/scheduler.go | 52 ++--- scheduler/scheduler_test.go | 20 +- snapd.go | 12 +- 22 files changed, 365 insertions(+), 365 deletions(-) rename core/{perror/perror.go => serror/serror.go} (99%) diff --git a/control/available_plugin.go b/control/available_plugin.go index c1e18bbef..7037e05c6 100644 --- a/control/available_plugin.go +++ b/control/available_plugin.go @@ -38,7 +38,7 @@ import ( "github.com/intelsdi-x/snap/control/plugin/client" "github.com/intelsdi-x/snap/control/routing" "github.com/intelsdi-x/snap/core/control_event" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" ) const ( @@ -481,7 +481,7 @@ func (p *apPool) subscriptionCount() int { return len(p.subs) } -func (p *apPool) selectAP(strat RoutingStrategy) (*availablePlugin, perror.SnapError) { +func (p *apPool) selectAP(strat RoutingStrategy) (*availablePlugin, serror.SnapError) { p.RLock() defer p.RUnlock() @@ -493,7 +493,7 @@ func (p *apPool) selectAP(strat RoutingStrategy) (*availablePlugin, perror.SnapE } sap, err := strat.Select(p, sp) if err != nil || sap == nil { - return nil, perror.New(err) + return nil, serror.New(err) } return sap.(*availablePlugin), nil } @@ -563,7 +563,7 @@ func (ap *availablePlugins) insert(pl *availablePlugin) error { if !exists { p, err := newPool(key, pl) if err != nil { - return perror.New(ErrBadKey, map[string]interface{}{ + return serror.New(ErrBadKey, map[string]interface{}{ "key": key, }) } @@ -574,21 +574,21 @@ func (ap *availablePlugins) insert(pl *availablePlugin) error { return nil } -func (ap *availablePlugins) getPool(key string) (*apPool, perror.SnapError) { +func (ap *availablePlugins) getPool(key string) (*apPool, serror.SnapError) { ap.RLock() defer ap.RUnlock() pool, ok := ap.table[key] if !ok { tnv := strings.Split(key, ":") if len(tnv) != 3 { - return nil, perror.New(ErrBadKey, map[string]interface{}{ + return nil, serror.New(ErrBadKey, map[string]interface{}{ "key": key, }) } v, err := strconv.Atoi(tnv[2]) if err != nil { - return nil, perror.New(ErrBadKey, map[string]interface{}{ + return nil, serror.New(ErrBadKey, map[string]interface{}{ "key": key, }) } @@ -603,7 +603,7 @@ func (ap *availablePlugins) getPool(key string) (*apPool, perror.SnapError) { return pool, nil } -func (ap *availablePlugins) holdPool(key string) (*apPool, perror.SnapError) { +func (ap *availablePlugins) holdPool(key string) (*apPool, serror.SnapError) { pool, err := ap.getPool(key) if err != nil { return nil, err @@ -615,7 +615,7 @@ func (ap *availablePlugins) holdPool(key string) (*apPool, perror.SnapError) { return pool, nil } -func (ap *availablePlugins) findLatestPool(pType, name string) (*apPool, perror.SnapError) { +func (ap *availablePlugins) findLatestPool(pType, name string) (*apPool, serror.SnapError) { // see if there exists a pool at all which matches name version. var latest *apPool for key, pool := range ap.table { @@ -652,7 +652,7 @@ func (ap *availablePlugins) getOrCreatePool(key string) (*apPool, error) { return pool, nil } -func (ap *availablePlugins) selectAP(key string) (*availablePlugin, perror.SnapError) { +func (ap *availablePlugins) selectAP(key string) (*availablePlugin, serror.SnapError) { ap.RLock() defer ap.RUnlock() diff --git a/control/control.go b/control/control.go index 38664b79a..567d1d813 100644 --- a/control/control.go +++ b/control/control.go @@ -42,7 +42,7 @@ import ( "github.com/intelsdi-x/snap/core/cdata" "github.com/intelsdi-x/snap/core/control_event" "github.com/intelsdi-x/snap/core/ctypes" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/pkg/aci" "github.com/intelsdi-x/snap/pkg/psigning" ) @@ -102,24 +102,24 @@ type managesPlugins interface { teardown() get(string) (*loadedPlugin, error) all() map[string]*loadedPlugin - LoadPlugin(*pluginDetails, gomit.Emitter) (*loadedPlugin, perror.SnapError) - UnloadPlugin(core.Plugin) (*loadedPlugin, perror.SnapError) + LoadPlugin(*pluginDetails, gomit.Emitter) (*loadedPlugin, serror.SnapError) + UnloadPlugin(core.Plugin) (*loadedPlugin, serror.SnapError) SetMetricCatalog(catalogsMetrics) GenerateArgs(pluginPath string) plugin.Arg SetPluginConfig(*pluginConfig) } type catalogsMetrics interface { - Get([]string, int) (*metricType, perror.SnapError) + Get([]string, int) (*metricType, serror.SnapError) Add(*metricType) AddLoadedMetricType(*loadedPlugin, core.Metric) RmUnloadedPluginMetrics(lp *loadedPlugin) - Fetch([]string) ([]*metricType, perror.SnapError) + Fetch([]string) ([]*metricType, serror.SnapError) Item() (string, []*metricType) Next() bool - Subscribe([]string, int) perror.SnapError - Unsubscribe([]string, int) perror.SnapError - GetPlugin([]string, int) (*loadedPlugin, perror.SnapError) + Subscribe([]string, int) serror.SnapError + Unsubscribe([]string, int) serror.SnapError + GetPlugin([]string, int) (*loadedPlugin, serror.SnapError) } type managesSigning interface { @@ -255,14 +255,14 @@ func (p *pluginControl) Stop() { // Load is the public method to load a plugin into // the LoadedPlugins array and issue an event when // successful. -func (p *pluginControl) Load(rp *core.RequestedPlugin) (core.CatalogedPlugin, perror.SnapError) { +func (p *pluginControl) Load(rp *core.RequestedPlugin) (core.CatalogedPlugin, serror.SnapError) { f := map[string]interface{}{ "_block": "load", } - details, perr := p.returnPluginDetails(rp) - if perr != nil { - return nil, perr + details, serr := p.returnPluginDetails(rp) + if serr != nil { + return nil, serr } if details.IsPackage { defer os.RemoveAll(filepath.Dir(details.ExecPath)) @@ -270,15 +270,15 @@ func (p *pluginControl) Load(rp *core.RequestedPlugin) (core.CatalogedPlugin, pe controlLogger.WithFields(f).Info("plugin load called") if !p.Started { - pe := perror.New(ErrControllerNotStarted) - pe.SetFields(f) - controlLogger.WithFields(f).Error(pe) - return nil, pe + se := serror.New(ErrControllerNotStarted) + se.SetFields(f) + controlLogger.WithFields(f).Error(se) + return nil, se } - pl, pe := p.pluginManager.LoadPlugin(details, p.eventManager) - if pe != nil { - return nil, pe + pl, se := p.pluginManager.LoadPlugin(details, p.eventManager) + if se != nil { + return nil, se } // If plugin was loaded from a package, remove ExecPath for @@ -298,7 +298,7 @@ func (p *pluginControl) Load(rp *core.RequestedPlugin) (core.CatalogedPlugin, pe return pl, nil } -func (p *pluginControl) verifySignature(rp *core.RequestedPlugin) (bool, perror.SnapError) { +func (p *pluginControl) verifySignature(rp *core.RequestedPlugin) (bool, serror.SnapError) { f := map[string]interface{}{ "_block": "verifySignature", } @@ -308,7 +308,7 @@ func (p *pluginControl) verifySignature(rp *core.RequestedPlugin) (bool, perror. case PluginTrustEnabled: err := p.signingManager.ValidateSignature(p.keyringFiles, rp.Path(), rp.Signature()) if err != nil { - return false, perror.New(err) + return false, serror.New(err) } case PluginTrustWarn: if rp.Signature() == nil { @@ -317,7 +317,7 @@ func (p *pluginControl) verifySignature(rp *core.RequestedPlugin) (bool, perror. } else { err := p.signingManager.ValidateSignature(p.keyringFiles, rp.Path(), rp.Signature()) if err != nil { - return false, perror.New(err) + return false, serror.New(err) } } } @@ -325,13 +325,13 @@ func (p *pluginControl) verifySignature(rp *core.RequestedPlugin) (bool, perror. } -func (p *pluginControl) returnPluginDetails(rp *core.RequestedPlugin) (*pluginDetails, perror.SnapError) { +func (p *pluginControl) returnPluginDetails(rp *core.RequestedPlugin) (*pluginDetails, serror.SnapError) { details := &pluginDetails{} - var perr perror.SnapError + var serr serror.SnapError //Check plugin signing - details.Signed, perr = p.verifySignature(rp) - if perr != nil { - return nil, perr + details.Signed, serr = p.verifySignature(rp) + if serr != nil { + return nil, serr } details.Path = rp.Path() @@ -341,19 +341,19 @@ func (p *pluginControl) returnPluginDetails(rp *core.RequestedPlugin) (*pluginDe if filepath.Ext(rp.Path()) == ".aci" { f, err := os.Open(rp.Path()) if err != nil { - return nil, perror.New(err) + return nil, serror.New(err) } defer f.Close() if err := aci.Validate(f); err != nil { - return nil, perror.New(err) + return nil, serror.New(err) } tempPath, err := aci.Extract(f) if err != nil { - return nil, perror.New(err) + return nil, serror.New(err) } details.ExecPath = path.Join(tempPath, "rootfs") if details.Manifest, err = aci.Manifest(f); err != nil { - return nil, perror.New(err) + return nil, serror.New(err) } details.Exec = details.Manifest.App.Exec[0] details.IsPackage = true @@ -366,7 +366,7 @@ func (p *pluginControl) returnPluginDetails(rp *core.RequestedPlugin) (*pluginDe return details, nil } -func (p *pluginControl) Unload(pl core.Plugin) (core.CatalogedPlugin, perror.SnapError) { +func (p *pluginControl) Unload(pl core.Plugin) (core.CatalogedPlugin, serror.SnapError) { up, err := p.pluginManager.UnloadPlugin(pl) if err != nil { return nil, err @@ -381,11 +381,11 @@ func (p *pluginControl) Unload(pl core.Plugin) (core.CatalogedPlugin, perror.Sna return up, nil } -func (p *pluginControl) SwapPlugins(in *core.RequestedPlugin, out core.CatalogedPlugin) perror.SnapError { +func (p *pluginControl) SwapPlugins(in *core.RequestedPlugin, out core.CatalogedPlugin) serror.SnapError { - details, perr := p.returnPluginDetails(in) - if perr != nil { - return perr + details, serr := p.returnPluginDetails(in) + if serr != nil { + return serr } if details.IsPackage { defer os.RemoveAll(filepath.Dir(details.ExecPath)) @@ -400,8 +400,8 @@ func (p *pluginControl) SwapPlugins(in *core.RequestedPlugin, out core.Cataloged if err != nil { _, err2 := p.pluginManager.UnloadPlugin(lp) if err2 != nil { - pe := perror.New(errors.New("failed to rollback after error")) - pe.SetFields(map[string]interface{}{ + se := serror.New(errors.New("failed to rollback after error")) + se.SetFields(map[string]interface{}{ "original-unload-error": err.Error(), "rollback-unload-error": err2.Error(), }) @@ -422,51 +422,51 @@ func (p *pluginControl) SwapPlugins(in *core.RequestedPlugin, out core.Cataloged return nil } -func (p *pluginControl) ValidateDeps(mts []core.Metric, plugins []core.SubscribedPlugin) []perror.SnapError { - var perrs []perror.SnapError +func (p *pluginControl) ValidateDeps(mts []core.Metric, plugins []core.SubscribedPlugin) []serror.SnapError { + var serrs []serror.SnapError for _, mt := range mts { _, errs := p.validateMetricTypeSubscription(mt, mt.Config()) if len(errs) > 0 { - perrs = append(perrs, errs...) + serrs = append(serrs, errs...) } } - if len(perrs) > 0 { - return perrs + if len(serrs) > 0 { + return serrs } //validate plugins for _, plg := range plugins { typ, err := core.ToPluginType(plg.TypeName()) if err != nil { - return []perror.SnapError{perror.New(err)} + return []serror.SnapError{serror.New(err)} } plg.Config().Merge(p.Config.Plugins.getPluginConfigDataNode(typ, plg.Name(), plg.Version())) errs := p.validatePluginSubscription(plg) if len(errs) > 0 { - perrs = append(perrs, errs...) - return perrs + serrs = append(serrs, errs...) + return serrs } } - return perrs + return serrs } -func (p *pluginControl) validatePluginSubscription(pl core.SubscribedPlugin) []perror.SnapError { - var perrs = []perror.SnapError{} +func (p *pluginControl) validatePluginSubscription(pl core.SubscribedPlugin) []serror.SnapError { + var serrs = []serror.SnapError{} controlLogger.WithFields(log.Fields{ "_block": "validate-plugin-subscription", "plugin": fmt.Sprintf("%s:%d", pl.Name(), pl.Version()), }).Info(fmt.Sprintf("validating dependencies for plugin %s:%d", pl.Name(), pl.Version())) lp, err := p.pluginManager.get(fmt.Sprintf("%s:%s:%d", pl.TypeName(), pl.Name(), pl.Version())) if err != nil { - pe := perror.New(fmt.Errorf("Plugin not found: type(%s) name(%s) version(%d)", pl.TypeName(), pl.Name(), pl.Version())) - pe.SetFields(map[string]interface{}{ + se := serror.New(fmt.Errorf("Plugin not found: type(%s) name(%s) version(%d)", pl.TypeName(), pl.Name(), pl.Version())) + se.SetFields(map[string]interface{}{ "name": pl.Name(), "version": pl.Version(), "type": pl.TypeName(), }) - perrs = append(perrs, pe) - return perrs + serrs = append(serrs, se) + return serrs } if lp.ConfigPolicy != nil { @@ -474,17 +474,17 @@ func (p *pluginControl) validatePluginSubscription(pl core.SubscribedPlugin) []p _, errs := ncd.Process(pl.Config().Table()) if errs != nil && errs.HasErrors() { for _, e := range errs.Errors() { - pe := perror.New(e) - pe.SetFields(map[string]interface{}{"name": pl.Name(), "version": pl.Version()}) - perrs = append(perrs, pe) + se := serror.New(e) + se.SetFields(map[string]interface{}{"name": pl.Name(), "version": pl.Version()}) + serrs = append(serrs, se) } } } - return perrs + return serrs } -func (p *pluginControl) validateMetricTypeSubscription(mt core.RequestedMetric, cd *cdata.ConfigDataNode) (core.Metric, []perror.SnapError) { - var perrs []perror.SnapError +func (p *pluginControl) validateMetricTypeSubscription(mt core.RequestedMetric, cd *cdata.ConfigDataNode) (core.Metric, []serror.SnapError) { + var serrs []serror.SnapError controlLogger.WithFields(log.Fields{ "_block": "validate-metric-subscription", "namespace": mt.Namespace(), @@ -493,21 +493,21 @@ func (p *pluginControl) validateMetricTypeSubscription(mt core.RequestedMetric, m, err := p.metricCatalog.Get(mt.Namespace(), mt.Version()) if err != nil { - perrs = append(perrs, err) - return nil, perrs + serrs = append(serrs, err) + return nil, serrs } // No metric found return error. if m == nil { - perrs = append(perrs, perror.New(errors.New(fmt.Sprintf("no metric found cannot subscribe: (%s) version(%d)", mt.Namespace(), mt.Version())))) - return nil, perrs + serrs = append(serrs, serror.New(errors.New(fmt.Sprintf("no metric found cannot subscribe: (%s) version(%d)", mt.Namespace(), mt.Version())))) + return nil, serrs } m.config = cd - typ, perr := core.ToPluginType(m.Plugin.TypeName()) - if perr != nil { - return nil, []perror.SnapError{perror.New(err)} + typ, serr := core.ToPluginType(m.Plugin.TypeName()) + if serr != nil { + return nil, []serror.SnapError{serror.New(err)} } // merge global plugin config @@ -522,26 +522,26 @@ func (p *pluginControl) validateMetricTypeSubscription(mt core.RequestedMetric, // Checking m.policy for nil will not work, we need to check if rules are nil. if m.policy.HasRules() { if m.Config() == nil { - perrs = append(perrs, perror.New(errors.New(fmt.Sprintf("Policy defined for metric, (%s) version (%d), but no config defined in manifest", mt.Namespace(), mt.Version())))) - return nil, perrs + serrs = append(serrs, serror.New(errors.New(fmt.Sprintf("Policy defined for metric, (%s) version (%d), but no config defined in manifest", mt.Namespace(), mt.Version())))) + return nil, serrs } ncdTable, errs := m.policy.Process(m.Config().Table()) if errs != nil && errs.HasErrors() { for _, e := range errs.Errors() { - perrs = append(perrs, perror.New(e)) + serrs = append(serrs, serror.New(e)) } - return nil, perrs + return nil, serrs } m.config = cdata.FromTable(*ncdTable) } - return m, perrs + return m, serrs } -func (p *pluginControl) gatherCollectors(mts []core.Metric) ([]core.Plugin, []perror.SnapError) { +func (p *pluginControl) gatherCollectors(mts []core.Metric) ([]core.Plugin, []serror.SnapError) { var ( plugins []core.Plugin - perrs []perror.SnapError + serrs []serror.SnapError ) // here we resolve and retrieve plugins for each metric type. @@ -553,7 +553,7 @@ func (p *pluginControl) gatherCollectors(mts []core.Metric) ([]core.Plugin, []pe for _, mt := range mts { m, err := p.metricCatalog.Get(mt.Namespace(), mt.Version()) if err != nil { - perrs = append(perrs, err) + serrs = append(serrs, err) continue } // if the metric subscription is to version -1, we need to carry @@ -567,8 +567,8 @@ func (p *pluginControl) gatherCollectors(mts []core.Metric) ([]core.Plugin, []pe colPlugins[m.Plugin.Key()] = m.Plugin } } - if len(perrs) > 0 { - return plugins, perrs + if len(serrs) > 0 { + return plugins, serrs } for _, lp := range colPlugins { @@ -578,12 +578,12 @@ func (p *pluginControl) gatherCollectors(mts []core.Metric) ([]core.Plugin, []pe return plugins, nil } -func (p *pluginControl) SubscribeDeps(taskId string, mts []core.Metric, plugins []core.Plugin) []perror.SnapError { - var perrs []perror.SnapError +func (p *pluginControl) SubscribeDeps(taskId string, mts []core.Metric, plugins []core.Plugin) []serror.SnapError { + var serrs []serror.SnapError collectors, errs := p.gatherCollectors(mts) if len(errs) > 0 { - perrs = append(perrs) + serrs = append(serrs) } plugins = append(plugins, collectors...) @@ -595,59 +595,59 @@ func (p *pluginControl) SubscribeDeps(taskId string, mts []core.Metric, plugins if sub.Version() < 1 { latest, err := p.pluginManager.get(fmt.Sprintf("%s:%s:%d", sub.TypeName(), sub.Name(), sub.Version())) if err != nil { - perrs = append(perrs, perror.New(err)) - return perrs + serrs = append(serrs, serror.New(err)) + return serrs } pool, err := p.pluginRunner.AvailablePlugins().getOrCreatePool(latest.Key()) if err != nil { - perrs = append(perrs, perror.New(err)) - return perrs + serrs = append(serrs, serror.New(err)) + return serrs } pool.subscribe(taskId, unboundSubscriptionType) if pool.eligible() { err = p.verifyPlugin(latest) if err != nil { - perrs = append(perrs, perror.New(err)) - return perrs + serrs = append(serrs, serror.New(err)) + return serrs } err = p.pluginRunner.runPlugin(latest.Details) if err != nil { - perrs = append(perrs, perror.New(err)) - return perrs + serrs = append(serrs, serror.New(err)) + return serrs } } } else { pool, err := p.pluginRunner.AvailablePlugins().getOrCreatePool(fmt.Sprintf("%s:%s:%d", sub.TypeName(), sub.Name(), sub.Version())) if err != nil { - perrs = append(perrs, perror.New(err)) - return perrs + serrs = append(serrs, serror.New(err)) + return serrs } pool.subscribe(taskId, boundSubscriptionType) if pool.eligible() { pl, err := p.pluginManager.get(fmt.Sprintf("%s:%s:%d", sub.TypeName(), sub.Name(), sub.Version())) if err != nil { - perrs = append(perrs, perror.New(err)) - return perrs + serrs = append(serrs, serror.New(err)) + return serrs } err = p.verifyPlugin(pl) if err != nil { - perrs = append(perrs, perror.New(err)) - return perrs + serrs = append(serrs, serror.New(err)) + return serrs } err = p.pluginRunner.runPlugin(pl.Details) if err != nil { - perrs = append(perrs, perror.New(err)) - return perrs + serrs = append(serrs, serror.New(err)) + return serrs } } } - perr := p.sendPluginSubscriptionEvent(taskId, sub) - if perr != nil { - perrs = append(perrs, perr) + serr := p.sendPluginSubscriptionEvent(taskId, sub) + if serr != nil { + serrs = append(serrs, serr) } } - return perrs + return serrs } func (p *pluginControl) verifyPlugin(lp *loadedPlugin) error { @@ -665,10 +665,10 @@ func (p *pluginControl) verifyPlugin(lp *loadedPlugin) error { return nil } -func (p *pluginControl) sendPluginSubscriptionEvent(taskId string, pl core.Plugin) perror.SnapError { +func (p *pluginControl) sendPluginSubscriptionEvent(taskId string, pl core.Plugin) serror.SnapError { pt, err := core.ToPluginType(pl.TypeName()) if err != nil { - return perror.New(err) + return serror.New(err) } e := &control_event.PluginSubscriptionEvent{ TaskId: taskId, @@ -681,42 +681,42 @@ func (p *pluginControl) sendPluginSubscriptionEvent(taskId string, pl core.Plugi e.SubscriptionType = int(boundSubscriptionType) } if _, err := p.eventManager.Emit(e); err != nil { - return perror.New(err) + return serror.New(err) } return nil } -func (p *pluginControl) UnsubscribeDeps(taskId string, mts []core.Metric, plugins []core.Plugin) []perror.SnapError { - var perrs []perror.SnapError +func (p *pluginControl) UnsubscribeDeps(taskId string, mts []core.Metric, plugins []core.Plugin) []serror.SnapError { + var serrs []serror.SnapError collectors, errs := p.gatherCollectors(mts) if len(errs) > 0 { - perrs = append(perrs, errs...) + serrs = append(serrs, errs...) } plugins = append(plugins, collectors...) for _, sub := range plugins { pool, err := p.pluginRunner.AvailablePlugins().getPool(fmt.Sprintf("%s:%s:%d", sub.TypeName(), sub.Name(), sub.Version())) if err != nil { - perrs = append(perrs, err) - return perrs + serrs = append(serrs, err) + return serrs } if pool != nil { pool.unsubscribe(taskId) } - perr := p.sendPluginUnsubscriptionEvent(taskId, sub) - if perr != nil { - perrs = append(perrs, perr) + serr := p.sendPluginUnsubscriptionEvent(taskId, sub) + if serr != nil { + serrs = append(serrs, serr) } } - return perrs + return serrs } -func (p *pluginControl) sendPluginUnsubscriptionEvent(taskId string, pl core.Plugin) perror.SnapError { +func (p *pluginControl) sendPluginUnsubscriptionEvent(taskId string, pl core.Plugin) serror.SnapError { pt, err := core.ToPluginType(pl.TypeName()) if err != nil { - return perror.New(err) + return serror.New(err) } e := &control_event.PluginUnsubscriptionEvent{ TaskId: taskId, @@ -725,7 +725,7 @@ func (p *pluginControl) sendPluginUnsubscriptionEvent(taskId string, pl core.Plu PluginVersion: pl.Version(), } if _, err := p.eventManager.Emit(e); err != nil { - return perror.New(err) + return serror.New(err) } return nil } diff --git a/control/control_test.go b/control/control_test.go index 3af118bce..fe3bcb3db 100644 --- a/control/control_test.go +++ b/control/control_test.go @@ -39,7 +39,7 @@ import ( "github.com/intelsdi-x/snap/core/cdata" "github.com/intelsdi-x/snap/core/control_event" "github.com/intelsdi-x/snap/core/ctypes" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" ) // Mock Executor used to test @@ -58,11 +58,11 @@ type MockPluginManagerBadSwap struct { loadedPlugins *loadedPlugins } -func (m *MockPluginManagerBadSwap) LoadPlugin(*pluginDetails, gomit.Emitter) (*loadedPlugin, perror.SnapError) { +func (m *MockPluginManagerBadSwap) LoadPlugin(*pluginDetails, gomit.Emitter) (*loadedPlugin, serror.SnapError) { return new(loadedPlugin), nil } -func (m *MockPluginManagerBadSwap) UnloadPlugin(c core.Plugin) (*loadedPlugin, perror.SnapError) { - return nil, perror.New(errors.New("fake")) +func (m *MockPluginManagerBadSwap) UnloadPlugin(c core.Plugin) (*loadedPlugin, serror.SnapError) { + return nil, serror.New(errors.New("fake")) } func (m *MockPluginManagerBadSwap) get(string) (*loadedPlugin, error) { return nil, nil } func (m *MockPluginManagerBadSwap) teardown() {} @@ -75,11 +75,11 @@ func (m *MockPluginManagerBadSwap) all() map[string]*loadedPlugin { return m.loadedPlugins.table } -func load(c *pluginControl, paths ...string) (core.CatalogedPlugin, perror.SnapError) { +func load(c *pluginControl, paths ...string) (core.CatalogedPlugin, serror.SnapError) { // This is a Travis optimized loading of plugins. From time to time, tests will error in Travis // due to a timeout when waiting for a response from a plugin. We are going to attempt loading a plugin // 3 times before letting the error through. Hopefully this cuts down on the number of Travis failures - var e perror.SnapError + var e serror.SnapError var p core.CatalogedPlugin rp, _ := core.NewRequestedPlugin(paths[0]) if len(paths) > 1 { @@ -556,9 +556,9 @@ type mc struct { e int } -func (m *mc) Fetch(ns []string) ([]*metricType, perror.SnapError) { +func (m *mc) Fetch(ns []string) ([]*metricType, serror.SnapError) { if m.e == 2 { - return nil, perror.New(errors.New("test")) + return nil, serror.New(errors.New("test")) } return nil, nil } @@ -567,29 +567,29 @@ func (m *mc) resolvePlugin(mns []string, ver int) (*loadedPlugin, error) { return nil, nil } -func (m *mc) GetPlugin([]string, int) (*loadedPlugin, perror.SnapError) { +func (m *mc) GetPlugin([]string, int) (*loadedPlugin, serror.SnapError) { return nil, nil } -func (m *mc) Get(ns []string, ver int) (*metricType, perror.SnapError) { +func (m *mc) Get(ns []string, ver int) (*metricType, serror.SnapError) { if m.e == 1 { return &metricType{ policy: &mockCDProc{}, }, nil } - return nil, perror.New(errorMetricNotFound(ns)) + return nil, serror.New(errorMetricNotFound(ns)) } -func (m *mc) Subscribe(ns []string, ver int) perror.SnapError { +func (m *mc) Subscribe(ns []string, ver int) serror.SnapError { if ns[0] == "nf" { - return perror.New(errorMetricNotFound(ns)) + return serror.New(errorMetricNotFound(ns)) } return nil } -func (m *mc) Unsubscribe(ns []string, ver int) perror.SnapError { +func (m *mc) Unsubscribe(ns []string, ver int) serror.SnapError { if ns[0] == "nf" { - return perror.New(errorMetricNotFound(ns)) + return serror.New(errorMetricNotFound(ns)) } if ns[0] == "neg" { return errNegativeSubCount diff --git a/control/metrics.go b/control/metrics.go index 13447c8a0..da99c3049 100644 --- a/control/metrics.go +++ b/control/metrics.go @@ -30,12 +30,12 @@ import ( "github.com/intelsdi-x/snap/core" "github.com/intelsdi-x/snap/core/cdata" "github.com/intelsdi-x/snap/core/ctypes" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" ) var ( errMetricNotFound = errors.New("metric not found") - errNegativeSubCount = perror.New(errors.New("subscription count cannot be < 0")) + errNegativeSubCount = serror.New(errors.New("subscription count cannot be < 0")) ) func errorMetricNotFound(ns []string, ver ...int) error { @@ -111,7 +111,7 @@ func (m *metricType) Subscribe() { m.subscriptions++ } -func (m *metricType) Unsubscribe() perror.SnapError { +func (m *metricType) Unsubscribe() serror.SnapError { if m.subscriptions == 0 { return errNegativeSubCount } @@ -210,14 +210,14 @@ func (mc *metricCatalog) Add(m *metricType) { // Get retrieves a loadedPlugin given a namespace and version. // If provided a version of -1 the latest plugin will be returned. -func (mc *metricCatalog) Get(ns []string, version int) (*metricType, perror.SnapError) { +func (mc *metricCatalog) Get(ns []string, version int) (*metricType, serror.SnapError) { mc.mutex.Lock() defer mc.mutex.Unlock() return mc.get(ns, version) } // Fetch transactionally retrieves all metrics which fall under namespace ns -func (mc *metricCatalog) Fetch(ns []string) ([]*metricType, perror.SnapError) { +func (mc *metricCatalog) Fetch(ns []string) ([]*metricType, serror.SnapError) { mc.mutex.Lock() defer mc.mutex.Unlock() @@ -260,7 +260,7 @@ func (mc *metricCatalog) Next() bool { } // Subscribe atomically increments a metric's subscription count in the table. -func (mc *metricCatalog) Subscribe(ns []string, version int) perror.SnapError { +func (mc *metricCatalog) Subscribe(ns []string, version int) serror.SnapError { mc.mutex.Lock() defer mc.mutex.Unlock() @@ -274,7 +274,7 @@ func (mc *metricCatalog) Subscribe(ns []string, version int) perror.SnapError { } // Unsubscribe atomically decrements a metric's count in the table -func (mc *metricCatalog) Unsubscribe(ns []string, version int) perror.SnapError { +func (mc *metricCatalog) Unsubscribe(ns []string, version int) serror.SnapError { mc.mutex.Lock() defer mc.mutex.Unlock() @@ -286,7 +286,7 @@ func (mc *metricCatalog) Unsubscribe(ns []string, version int) perror.SnapError return m.Unsubscribe() } -func (mc *metricCatalog) GetPlugin(mns []string, ver int) (*loadedPlugin, perror.SnapError) { +func (mc *metricCatalog) GetPlugin(mns []string, ver int) (*loadedPlugin, serror.SnapError) { m, err := mc.Get(mns, ver) if err != nil { return nil, err @@ -294,24 +294,24 @@ func (mc *metricCatalog) GetPlugin(mns []string, ver int) (*loadedPlugin, perror return m.Plugin, nil } -func (mc *metricCatalog) get(ns []string, ver int) (*metricType, perror.SnapError) { +func (mc *metricCatalog) get(ns []string, ver int) (*metricType, serror.SnapError) { mts, err := mc.tree.Get(ns) if err != nil { return nil, err } if mts == nil { - return nil, perror.New(errMetricNotFound) + return nil, serror.New(errMetricNotFound) } // a version IS given if ver > 0 { l, err := getVersion(mts, ver) if err != nil { - pe := perror.New(errorMetricNotFound(ns, ver)) - pe.SetFields(map[string]interface{}{ + se := serror.New(errorMetricNotFound(ns, ver)) + se.SetFields(map[string]interface{}{ "name": core.JoinNamespace(ns), "version": ver, }) - return nil, pe + return nil, se } return l, nil } @@ -343,11 +343,11 @@ func appendIfMissing(keys []string, ns string) []string { return append(keys, ns) } -func getVersion(c []*metricType, ver int) (*metricType, perror.SnapError) { +func getVersion(c []*metricType, ver int) (*metricType, serror.SnapError) { for _, m := range c { if m.Plugin.Version() == ver { return m, nil } } - return nil, perror.New(errMetricNotFound) + return nil, serror.New(errMetricNotFound) } diff --git a/control/mttrie.go b/control/mttrie.go index 8363671c5..05e37135e 100644 --- a/control/mttrie.go +++ b/control/mttrie.go @@ -24,7 +24,7 @@ import ( "fmt" "github.com/intelsdi-x/snap/core" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" ) /* @@ -146,7 +146,7 @@ func (mtt *mttNode) Add(mt *metricType) { // Collect collects all children below a given namespace // and concatenates their metric types into a single slice -func (mtt *mttNode) Fetch(ns []string) ([]*metricType, perror.SnapError) { +func (mtt *mttNode) Fetch(ns []string) ([]*metricType, serror.SnapError) { node, err := mtt.find(ns) if err != nil { return nil, err @@ -171,7 +171,7 @@ func (mtt *mttNode) Fetch(ns []string) ([]*metricType, perror.SnapError) { } // Remove removes all children below a given namespace -func (mtt *mttNode) Remove(ns []string) perror.SnapError { +func (mtt *mttNode) Remove(ns []string) serror.SnapError { _, err := mtt.find(ns) if err != nil { return err @@ -189,17 +189,17 @@ func (mtt *mttNode) Remove(ns []string) perror.SnapError { // Get works like fetch, but only returns the MT at the given node // and does not gather the node's children. -func (mtt *mttNode) Get(ns []string) ([]*metricType, perror.SnapError) { +func (mtt *mttNode) Get(ns []string) ([]*metricType, serror.SnapError) { node, err := mtt.find(ns) if err != nil { return nil, err } if node.mts == nil { - pe := perror.New(errorMetricNotFound(ns)) - pe.SetFields(map[string]interface{}{ + se := serror.New(errorMetricNotFound(ns)) + se.SetFields(map[string]interface{}{ "name": core.JoinNamespace(ns), }) - return nil, pe + return nil, se } var mts []*metricType for _, mt := range node.mts { @@ -226,14 +226,14 @@ func (mtt *mttNode) walk(ns []string) (*mttNode, int) { return parent, len(ns) } -func (mtt *mttNode) find(ns []string) (*mttNode, perror.SnapError) { +func (mtt *mttNode) find(ns []string) (*mttNode, serror.SnapError) { node, index := mtt.walk(ns) if index != len(ns) { - pe := perror.New(errorMetricNotFound(ns)) - pe.SetFields(map[string]interface{}{ + se := serror.New(errorMetricNotFound(ns)) + se.SetFields(map[string]interface{}{ "name": core.JoinNamespace(ns), }) - return nil, pe + return nil, se } return node, nil } diff --git a/control/plugin/client/httpjsonrpc_test.go b/control/plugin/client/httpjsonrpc_test.go index da1f1be08..7ea84c272 100644 --- a/control/plugin/client/httpjsonrpc_test.go +++ b/control/plugin/client/httpjsonrpc_test.go @@ -235,11 +235,11 @@ func TestHTTPJSONRPC(t *testing.T) { So(cp.Get([]string{"foo", "bar"}), ShouldNotBeNil) node := cp.Get([]string{"foo", "bar"}) So(node, ShouldNotBeNil) - cpn, cperrs := node.Process(mts[0].Config().Table()) + cpn, cserrs := node.Process(mts[0].Config().Table()) So(cpn, ShouldNotBeNil) So((*cpn)["somefloat"].Type(), ShouldResemble, "float") So((*cpn)["somefloat"].(*ctypes.ConfigValueFloat).Value, ShouldResemble, 3.14) - So(cperrs.Errors(), ShouldBeEmpty) + So(cserrs.Errors(), ShouldBeEmpty) }) }) @@ -268,11 +268,11 @@ func TestHTTPJSONRPC(t *testing.T) { node := cp.Get([]string{"foo", "bar"}) So(node, ShouldNotBeNil) So(err, ShouldBeNil) - _, cperrs := node.Process(mts[0].Config().Table()) + _, cserrs := node.Process(mts[0].Config().Table()) //So(cpn, ShouldBeNil) - So(cperrs.Errors(), ShouldNotBeEmpty) - So(len(cperrs.Errors()), ShouldEqual, 1) - So(cperrs.Errors()[0].Error(), ShouldContainSubstring, "password") + So(cserrs.Errors(), ShouldNotBeEmpty) + So(len(cserrs.Errors()), ShouldEqual, 1) + So(cserrs.Errors()[0].Error(), ShouldContainSubstring, "password") }) }) }) diff --git a/control/plugin_manager.go b/control/plugin_manager.go index 0ad1733cf..715a086fd 100644 --- a/control/plugin_manager.go +++ b/control/plugin_manager.go @@ -41,7 +41,7 @@ import ( "github.com/intelsdi-x/snap/control/plugin/client" "github.com/intelsdi-x/snap/control/plugin/cpolicy" "github.com/intelsdi-x/snap/core" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" ) const ( @@ -76,12 +76,12 @@ func newLoadedPlugins() *loadedPlugins { } // add adds a loadedPlugin pointer to the table -func (l *loadedPlugins) add(lp *loadedPlugin) perror.SnapError { +func (l *loadedPlugins) add(lp *loadedPlugin) serror.SnapError { l.Lock() defer l.Unlock() if _, exists := l.table[lp.Key()]; exists { - return perror.New(ErrPluginAlreadyLoaded, map[string]interface{}{ + return serror.New(ErrPluginAlreadyLoaded, map[string]interface{}{ "plugin-name": lp.Meta.Name, "plugin-version": lp.Meta.Version, "plugin-type": lp.Type.String(), @@ -254,7 +254,7 @@ func (p *pluginManager) SetMetricCatalog(mc catalogsMetrics) { // Load is the method for loading a plugin and // saving plugin into the LoadedPlugins array -func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter) (*loadedPlugin, perror.SnapError) { +func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter) (*loadedPlugin, serror.SnapError) { lPlugin := new(loadedPlugin) lPlugin.Details = details lPlugin.State = DetectedState @@ -270,7 +270,7 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter "_block": "load-plugin", "error": err.Error(), }).Error("load plugin error while creating executable plugin") - return nil, perror.New(err) + return nil, serror.New(err) } err = ePlugin.Start() @@ -279,7 +279,7 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter "_block": "load-plugin", "error": err.Error(), }).Error("load plugin error while starting plugin") - return nil, perror.New(err) + return nil, serror.New(err) } var resp *plugin.Response @@ -290,7 +290,7 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter "_block": "load-plugin", "error": err.Error(), }).Error("load plugin error while waiting for response from plugin") - return nil, perror.New(err) + return nil, serror.New(err) } ap, err := newAvailablePlugin(resp, emitter, ePlugin) @@ -299,7 +299,7 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter "_block": "load-plugin", "error": err.Error(), }).Error("load plugin error while creating available plugin") - return nil, perror.New(err) + return nil, serror.New(err) } if resp.Meta.Unsecure { @@ -312,13 +312,13 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter "_block": "load-plugin", "error": err.Error(), }).Error("load plugin error while pinging the plugin") - return nil, perror.New(err) + return nil, serror.New(err) } // Get the ConfigPolicy and add it to the loaded plugin c, ok := ap.client.(plugin.Plugin) if !ok { - return nil, perror.New(errors.New("missing GetConfigPolicy function")) + return nil, serror.New(errors.New("missing GetConfigPolicy function")) } cp, err := c.GetConfigPolicy() if err != nil { @@ -330,7 +330,7 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter "plugin-version": ap.Version(), "plugin-id": ap.ID(), }).Error("error in getting config policy") - return nil, perror.New(err) + return nil, serror.New(err) } lPlugin.ConfigPolicy = cp @@ -348,7 +348,7 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter "plugin-type": "collector", "error": err.Error(), }).Error("error in getting metric types") - return nil, perror.New(err) + return nil, serror.New(err) } // The plugin cache client will be integrated here later @@ -384,7 +384,7 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter "metric-version": nmt.Version(), "error": err.Error(), }).Error("received metric with bad version") - return nil, perror.New(err) + return nil, serror.New(err) } p.metricCatalog.AddLoadedMetricType(lPlugin, nmt) } @@ -396,7 +396,7 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter "_block": "load-plugin", "error": err.Error(), }).Error("load plugin error while killing plugin executable plugin") - return nil, perror.New(err) + return nil, serror.New(err) } if resp.State != plugin.PluginSuccess { @@ -406,7 +406,7 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter "error": e, "plugin response": resp.ErrorMessage, }).Error("load plugin error") - return nil, perror.New(e) + return nil, serror.New(e) } lPlugin.Meta = resp.Meta @@ -428,25 +428,25 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter } // unloads a plugin from the LoadedPlugins table -func (p *pluginManager) UnloadPlugin(pl core.Plugin) (*loadedPlugin, perror.SnapError) { +func (p *pluginManager) UnloadPlugin(pl core.Plugin) (*loadedPlugin, serror.SnapError) { plugin, err := p.loadedPlugins.get(fmt.Sprintf("%s:%s:%d", pl.TypeName(), pl.Name(), pl.Version())) if err != nil { - pe := perror.New(ErrPluginNotFound, map[string]interface{}{ + se := serror.New(ErrPluginNotFound, map[string]interface{}{ "plugin-name": pl.Name(), "plugin-version": pl.Version(), "plugin-type": pl.TypeName(), }) - return nil, pe + return nil, se } if plugin.State != LoadedState { - pe := perror.New(ErrPluginNotInLoadedState, map[string]interface{}{ + se := serror.New(ErrPluginNotInLoadedState, map[string]interface{}{ "plugin-name": plugin.Name(), "plugin-version": plugin.Version(), "plugin-type": pl.TypeName(), }) - return nil, pe + return nil, se } // If the plugin was loaded from os.TempDir() clean up @@ -464,14 +464,14 @@ func (p *pluginManager) UnloadPlugin(pl core.Plugin) (*loadedPlugin, perror.Snap "plugin-version": plugin.Version(), "plugin-path": plugin.Details.Path, }).Error(err) - pe := perror.New(err) - pe.SetFields(map[string]interface{}{ + se := serror.New(err) + se.SetFields(map[string]interface{}{ "plugin-type": plugin.TypeName(), "plugin-name": plugin.Name(), "plugin-version": plugin.Version(), "plugin-path": plugin.Details.Path, }) - return nil, pe + return nil, se } } diff --git a/control/plugin_manager_test.go b/control/plugin_manager_test.go index ea853db0c..fac02eada 100644 --- a/control/plugin_manager_test.go +++ b/control/plugin_manager_test.go @@ -31,7 +31,7 @@ import ( "github.com/intelsdi-x/snap/control/plugin" "github.com/intelsdi-x/snap/core/ctypes" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" ) var ( @@ -72,11 +72,11 @@ func TestLoadedPlugins(t *testing.T) { }) } -func loadPlugin(p *pluginManager, path string) (*loadedPlugin, perror.SnapError) { +func loadPlugin(p *pluginManager, path string) (*loadedPlugin, serror.SnapError) { // This is a Travis optimized loading of plugins. From time to time, tests will error in Travis // due to a timeout when waiting for a response from a plugin. We are going to attempt loading a plugin // 3 times before letting the error through. Hopefully this cuts down on the number of Travis failures - var e perror.SnapError + var e serror.SnapError var lp *loadedPlugin details := &pluginDetails{ Path: path, diff --git a/core/perror/perror.go b/core/serror/serror.go similarity index 99% rename from core/perror/perror.go rename to core/serror/serror.go index d85d5151f..713d36cce 100644 --- a/core/perror/perror.go +++ b/core/serror/serror.go @@ -17,7 +17,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package perror +package serror type SnapError interface { error diff --git a/core/task.go b/core/task.go index d865e78f5..8de46867e 100644 --- a/core/task.go +++ b/core/task.go @@ -24,7 +24,7 @@ import ( log "github.com/Sirupsen/logrus" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/pkg/schedule" "github.com/intelsdi-x/snap/scheduler/wmap" ) @@ -140,5 +140,5 @@ func SetTaskID(id string) TaskOption { } type TaskErrors interface { - Errors() []perror.SnapError + Errors() []serror.SnapError } diff --git a/mgmt/rest/client/plugin.go b/mgmt/rest/client/plugin.go index 6b598151a..5608f9730 100644 --- a/mgmt/rest/client/plugin.go +++ b/mgmt/rest/client/plugin.go @@ -24,7 +24,7 @@ import ( "net/url" "time" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/mgmt/rest/rbody" ) @@ -34,7 +34,7 @@ func (c *Client) LoadPlugin(p []string) *LoadPluginResult { r := new(LoadPluginResult) resp, err := c.pluginUploadRequest(p) if err != nil { - r.Err = perror.New(err) + r.Err = serror.New(err) return r } @@ -48,9 +48,9 @@ func (c *Client) LoadPlugin(p []string) *LoadPluginResult { for k, v := range f { fields[k] = v } - r.Err = perror.New(resp.Body.(*rbody.Error), fields) + r.Err = serror.New(resp.Body.(*rbody.Error), fields) default: - r.Err = perror.New(ErrAPIResponseMetaType) + r.Err = serror.New(ErrAPIResponseMetaType) } return r } @@ -122,7 +122,7 @@ type GetPluginsResult struct { // LoadPluginResult is the response from snap/client on a LoadPlugin call. type LoadPluginResult struct { LoadedPlugins []LoadedPlugin - Err perror.SnapError + Err serror.SnapError } // UnloadPluginResponse is the response from snap/client on an UnloadPlugin call. diff --git a/mgmt/rest/plugin.go b/mgmt/rest/plugin.go index 5919d48f1..77a096f13 100644 --- a/mgmt/rest/plugin.go +++ b/mgmt/rest/plugin.go @@ -39,7 +39,7 @@ import ( "github.com/julienschmidt/httprouter" "github.com/intelsdi-x/snap/core" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/mgmt/rest/rbody" ) @@ -220,32 +220,32 @@ func (s *Server) unloadPlugin(w http.ResponseWriter, r *http.Request, p httprout } if iErr != nil { - pe := perror.New(errors.New("invalid version")) - pe.SetFields(f) - respond(400, rbody.FromSnapError(pe), w) + se := serror.New(errors.New("invalid version")) + se.SetFields(f) + respond(400, rbody.FromSnapError(se), w) return } if plName == "" { - pe := perror.New(errors.New("missing plugin name")) - pe.SetFields(f) - respond(400, rbody.FromSnapError(pe), w) + se := serror.New(errors.New("missing plugin name")) + se.SetFields(f) + respond(400, rbody.FromSnapError(se), w) return } if plType == "" { - pe := perror.New(errors.New("missing plugin type")) - pe.SetFields(f) - respond(400, rbody.FromSnapError(pe), w) + se := serror.New(errors.New("missing plugin type")) + se.SetFields(f) + respond(400, rbody.FromSnapError(se), w) return } - up, pe := s.mm.Unload(&plugin{ + up, se := s.mm.Unload(&plugin{ name: plName, version: int(plVersion), pluginType: plType, }) - if pe != nil { - pe.SetFields(f) - respond(500, rbody.FromSnapError(pe), w) + if se != nil { + se.SetFields(f) + respond(500, rbody.FromSnapError(se), w) return } pr := &rbody.PluginUnloaded{ @@ -321,22 +321,22 @@ func (s *Server) getPlugin(w http.ResponseWriter, r *http.Request, p httprouter. } if iErr != nil { - pe := perror.New(errors.New("invalid version")) - pe.SetFields(f) - respond(400, rbody.FromSnapError(pe), w) + se := serror.New(errors.New("invalid version")) + se.SetFields(f) + respond(400, rbody.FromSnapError(se), w) return } if plName == "" { - pe := perror.New(errors.New("missing plugin name")) - pe.SetFields(f) - respond(400, rbody.FromSnapError(pe), w) + se := serror.New(errors.New("missing plugin name")) + se.SetFields(f) + respond(400, rbody.FromSnapError(se), w) return } if plType == "" { - pe := perror.New(errors.New("missing plugin type")) - pe.SetFields(f) - respond(400, rbody.FromSnapError(pe), w) + se := serror.New(errors.New("missing plugin type")) + se.SetFields(f) + respond(400, rbody.FromSnapError(se), w) return } @@ -351,8 +351,8 @@ func (s *Server) getPlugin(w http.ResponseWriter, r *http.Request, p httprouter. } } if plugin == nil { - pe := perror.New(ErrPluginNotFound, f) - respond(404, rbody.FromSnapError(pe), w) + se := serror.New(ErrPluginNotFound, f) + respond(404, rbody.FromSnapError(se), w) return } @@ -362,8 +362,8 @@ func (s *Server) getPlugin(w http.ResponseWriter, r *http.Request, p httprouter. b, err := ioutil.ReadFile(plugin.PluginPath()) if err != nil { f["plugin-path"] = plugin.PluginPath() - pe := perror.New(err, f) - respond(500, rbody.FromSnapError(pe), w) + se := serror.New(err, f) + respond(500, rbody.FromSnapError(se), w) return } @@ -373,8 +373,8 @@ func (s *Server) getPlugin(w http.ResponseWriter, r *http.Request, p httprouter. _, err = gz.Write(b) if err != nil { f["plugin-path"] = plugin.PluginPath() - pe := perror.New(err, f) - respond(500, rbody.FromSnapError(pe), w) + se := serror.New(err, f) + respond(500, rbody.FromSnapError(se), w) return } return diff --git a/mgmt/rest/rbody/error.go b/mgmt/rest/rbody/error.go index b9746f768..1556e10c4 100644 --- a/mgmt/rest/rbody/error.go +++ b/mgmt/rest/rbody/error.go @@ -22,7 +22,7 @@ package rbody import ( "fmt" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" ) const ( @@ -35,7 +35,7 @@ type Error struct { Fields map[string]string `json:"fields"` } -func FromSnapError(pe perror.SnapError) *Error { +func FromSnapError(pe serror.SnapError) *Error { e := &Error{ErrorMessage: pe.Error(), Fields: make(map[string]string)} // Convert into string format for k, v := range pe.Fields() { @@ -44,7 +44,7 @@ func FromSnapError(pe perror.SnapError) *Error { return e } -func FromSnapErrors(errs []perror.SnapError) *Error { +func FromSnapErrors(errs []serror.SnapError) *Error { fields := make(map[string]string) var msg string for i, err := range errs { diff --git a/mgmt/rest/server.go b/mgmt/rest/server.go index 901cba2ec..b5ffb5e8b 100644 --- a/mgmt/rest/server.go +++ b/mgmt/rest/server.go @@ -36,7 +36,7 @@ import ( "github.com/intelsdi-x/snap/core" "github.com/intelsdi-x/snap/core/cdata" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/mgmt/rest/rbody" "github.com/intelsdi-x/snap/mgmt/tribe/agreement" cschedule "github.com/intelsdi-x/snap/pkg/schedule" @@ -58,8 +58,8 @@ type managesMetrics interface { MetricCatalog() ([]core.CatalogedMetric, error) FetchMetrics([]string, int) ([]core.CatalogedMetric, error) GetMetric([]string, int) (core.CatalogedMetric, error) - Load(*core.RequestedPlugin) (core.CatalogedPlugin, perror.SnapError) - Unload(core.Plugin) (core.CatalogedPlugin, perror.SnapError) + Load(*core.RequestedPlugin) (core.CatalogedPlugin, serror.SnapError) + Unload(core.Plugin) (core.CatalogedPlugin, serror.SnapError) PluginCatalog() core.PluginCatalog AvailablePlugins() []core.AvailablePlugin GetAutodiscoverPaths() []string @@ -69,20 +69,20 @@ type managesTasks interface { CreateTask(cschedule.Schedule, *wmap.WorkflowMap, bool, ...core.TaskOption) (core.Task, core.TaskErrors) GetTasks() map[string]core.Task GetTask(string) (core.Task, error) - StartTask(string) []perror.SnapError - StopTask(string) []perror.SnapError + StartTask(string) []serror.SnapError + StopTask(string) []serror.SnapError RemoveTask(string) error WatchTask(string, core.TaskWatcherHandler) (core.TaskWatcherCloser, error) EnableTask(string) (core.Task, error) } type managesTribe interface { - GetAgreement(name string) (*agreement.Agreement, perror.SnapError) + GetAgreement(name string) (*agreement.Agreement, serror.SnapError) GetAgreements() map[string]*agreement.Agreement - AddAgreement(name string) perror.SnapError - RemoveAgreement(name string) perror.SnapError - JoinAgreement(agreementName, memberName string) perror.SnapError - LeaveAgreement(agreementName, memberName string) perror.SnapError + 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 } diff --git a/mgmt/rest/tribe.go b/mgmt/rest/tribe.go index 85e00db46..a9073247d 100644 --- a/mgmt/rest/tribe.go +++ b/mgmt/rest/tribe.go @@ -27,7 +27,7 @@ import ( log "github.com/Sirupsen/logrus" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/mgmt/rest/rbody" "github.com/julienschmidt/httprouter" ) @@ -56,15 +56,15 @@ func (s *Server) getAgreement(w http.ResponseWriter, r *http.Request, p httprout "agreement_name": name, } tribeLogger.WithFields(fields).Error(ErrAgreementDoesNotExist) - respond(400, rbody.FromSnapError(perror.New(ErrAgreementDoesNotExist, fields)), w) + respond(400, rbody.FromSnapError(serror.New(ErrAgreementDoesNotExist, fields)), w) return } a := &rbody.TribeGetAgreement{} - var perr perror.SnapError - a.Agreement, perr = s.tr.GetAgreement(name) - if perr != nil { - tribeLogger.Error(perr) - respond(400, rbody.FromSnapError(perr), w) + var serr serror.SnapError + a.Agreement, serr = s.tr.GetAgreement(name) + if serr != nil { + tribeLogger.Error(serr) + respond(400, rbody.FromSnapError(serr), w) return } respond(200, a, w) @@ -78,15 +78,15 @@ func (s *Server) deleteAgreement(w http.ResponseWriter, r *http.Request, p httpr "agreement_name": name, } tribeLogger.WithFields(fields).Error(ErrAgreementDoesNotExist) - respond(400, rbody.FromSnapError(perror.New(ErrAgreementDoesNotExist, fields)), w) + respond(400, rbody.FromSnapError(serror.New(ErrAgreementDoesNotExist, fields)), w) return } - var perr perror.SnapError - perr = s.tr.RemoveAgreement(name) - if perr != nil { - tribeLogger.Error(perr) - respond(400, rbody.FromSnapError(perr), w) + var serr serror.SnapError + serr = s.tr.RemoveAgreement(name) + if serr != nil { + tribeLogger.Error(serr) + respond(400, rbody.FromSnapError(serr), w) return } @@ -103,7 +103,7 @@ func (s *Server) joinAgreement(w http.ResponseWriter, r *http.Request, p httprou "agreement_name": name, } tribeLogger.WithFields(fields).Error(ErrAgreementDoesNotExist) - respond(400, rbody.FromSnapError(perror.New(ErrAgreementDoesNotExist, fields)), w) + respond(400, rbody.FromSnapError(serror.New(ErrAgreementDoesNotExist, fields)), w) return } @@ -123,16 +123,16 @@ func (s *Server) joinAgreement(w http.ResponseWriter, r *http.Request, p httprou "error": err, "hint": `The body of the request should be of the form '{"member_name": "some_value"}'`, } - pe := perror.New(ErrInvalidJSON, fields) + se := serror.New(ErrInvalidJSON, fields) tribeLogger.WithFields(fields).Error(ErrInvalidJSON) - respond(400, rbody.FromSnapError(pe), w) + respond(400, rbody.FromSnapError(se), w) return } - perr := s.tr.JoinAgreement(name, m.MemberName) - if perr != nil { - tribeLogger.Error(perr) - respond(400, rbody.FromSnapError(perr), w) + serr := s.tr.JoinAgreement(name, m.MemberName) + if serr != nil { + tribeLogger.Error(serr) + respond(400, rbody.FromSnapError(serr), w) return } agreement, _ := s.tr.GetAgreement(name) @@ -148,7 +148,7 @@ func (s *Server) leaveAgreement(w http.ResponseWriter, r *http.Request, p httpro "agreement_name": name, } tribeLogger.WithFields(fields).Error(ErrAgreementDoesNotExist) - respond(400, rbody.FromSnapError(perror.New(ErrAgreementDoesNotExist, fields)), w) + respond(400, rbody.FromSnapError(serror.New(ErrAgreementDoesNotExist, fields)), w) return } @@ -168,16 +168,16 @@ func (s *Server) leaveAgreement(w http.ResponseWriter, r *http.Request, p httpro "error": err, "hint": `The body of the request should be of the form '{"member_name": "some_value"}'`, } - pe := perror.New(ErrInvalidJSON, fields) + se := serror.New(ErrInvalidJSON, fields) tribeLogger.WithFields(fields).Error(ErrInvalidJSON) - respond(400, rbody.FromSnapError(pe), w) + respond(400, rbody.FromSnapError(se), w) return } - perr := s.tr.LeaveAgreement(name, m.MemberName) - if perr != nil { - tribeLogger.Error(perr) - respond(400, rbody.FromSnapError(perr), w) + serr := s.tr.LeaveAgreement(name, m.MemberName) + if serr != nil { + tribeLogger.Error(serr) + respond(400, rbody.FromSnapError(serr), w) return } agreement, _ := s.tr.GetAgreement(name) @@ -198,7 +198,7 @@ func (s *Server) getMember(w http.ResponseWriter, r *http.Request, p httprouter. "name": name, } tribeLogger.WithFields(fields).Error(ErrMemberNotFound) - respond(404, rbody.FromSnapError(perror.New(ErrMemberNotFound, fields)), w) + respond(404, rbody.FromSnapError(serror.New(ErrMemberNotFound, fields)), w) return } resp := &rbody.TribeMemberShow{ @@ -232,9 +232,9 @@ func (s *Server) addAgreement(w http.ResponseWriter, r *http.Request, p httprout "error": err, "hint": `The body of the request should be of the form '{"name": "agreement_name"}'`, } - pe := perror.New(ErrInvalidJSON, fields) + se := serror.New(ErrInvalidJSON, fields) tribeLogger.WithFields(fields).Error(ErrInvalidJSON) - respond(400, rbody.FromSnapError(pe), w) + respond(400, rbody.FromSnapError(se), w) return } @@ -242,9 +242,9 @@ func (s *Server) addAgreement(w http.ResponseWriter, r *http.Request, p httprout fields := map[string]interface{}{ "hint": `The body of the request should be of the form '{"name": "agreement_name"}'`, } - pe := perror.New(ErrInvalidJSON, fields) + se := serror.New(ErrInvalidJSON, fields) tribeLogger.WithFields(fields).Error(ErrInvalidJSON) - respond(400, rbody.FromSnapError(pe), w) + respond(400, rbody.FromSnapError(se), w) return } diff --git a/mgmt/tribe/tribe.go b/mgmt/tribe/tribe.go index e2f7443ec..6fb973d5d 100644 --- a/mgmt/tribe/tribe.go +++ b/mgmt/tribe/tribe.go @@ -33,8 +33,8 @@ import ( "github.com/intelsdi-x/gomit" "github.com/intelsdi-x/snap/core" "github.com/intelsdi-x/snap/core/control_event" - "github.com/intelsdi-x/snap/core/perror" "github.com/intelsdi-x/snap/core/scheduler_event" + "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/mgmt/tribe/agreement" "github.com/intelsdi-x/snap/mgmt/tribe/worker" "github.com/pborman/uuid" @@ -477,7 +477,7 @@ func (t *tribe) GetMembers() []string { return members } -func (t *tribe) LeaveAgreement(agreementName, memberName string) perror.SnapError { +func (t *tribe) LeaveAgreement(agreementName, memberName string) serror.SnapError { if err := t.canLeaveAgreement(agreementName, memberName); err != nil { return err } @@ -495,7 +495,7 @@ func (t *tribe) LeaveAgreement(agreementName, memberName string) perror.SnapErro return nil } -func (t *tribe) JoinAgreement(agreementName, memberName string) perror.SnapError { +func (t *tribe) JoinAgreement(agreementName, memberName string) serror.SnapError { if err := t.canJoinAgreement(agreementName, memberName); err != nil { return err } @@ -547,10 +547,10 @@ func (t *tribe) RemovePlugin(agreementName string, p agreement.Plugin) error { return nil } -func (t *tribe) GetAgreement(name string) (*agreement.Agreement, perror.SnapError) { +func (t *tribe) GetAgreement(name string) (*agreement.Agreement, serror.SnapError) { a, ok := t.agreements[name] if !ok { - return nil, perror.New(errAgreementDoesNotExist, map[string]interface{}{"agreement_name": name}) + return nil, serror.New(errAgreementDoesNotExist, map[string]interface{}{"agreement_name": name}) } return a, nil } @@ -559,7 +559,7 @@ func (t *tribe) GetAgreements() map[string]*agreement.Agreement { return t.agreements } -func (t *tribe) AddTask(agreementName string, task agreement.Task) perror.SnapError { +func (t *tribe) AddTask(agreementName string, task agreement.Task) serror.SnapError { if err := t.canAddTask(task, agreementName); err != nil { return err } @@ -577,7 +577,7 @@ func (t *tribe) AddTask(agreementName string, task agreement.Task) perror.SnapEr return nil } -func (t *tribe) RemoveTask(agreementName string, task agreement.Task) perror.SnapError { +func (t *tribe) RemoveTask(agreementName string, task agreement.Task) serror.SnapError { if err := t.canStartStopRemoveTask(task, agreementName); err != nil { return err } @@ -594,7 +594,7 @@ func (t *tribe) RemoveTask(agreementName string, task agreement.Task) perror.Sna return nil } -func (t *tribe) StopTask(agreementName string, task agreement.Task) perror.SnapError { +func (t *tribe) StopTask(agreementName string, task agreement.Task) serror.SnapError { if err := t.canStartStopRemoveTask(task, agreementName); err != nil { return err } @@ -611,7 +611,7 @@ func (t *tribe) StopTask(agreementName string, task agreement.Task) perror.SnapE return nil } -func (t *tribe) StartTask(agreementName string, task agreement.Task) perror.SnapError { +func (t *tribe) StartTask(agreementName string, task agreement.Task) serror.SnapError { if err := t.canStartStopRemoveTask(task, agreementName); err != nil { return err } @@ -629,12 +629,12 @@ func (t *tribe) StartTask(agreementName string, task agreement.Task) perror.Snap return nil } -func (t *tribe) AddAgreement(name string) perror.SnapError { +func (t *tribe) AddAgreement(name string) serror.SnapError { if _, ok := t.agreements[name]; ok { fields := log.Fields{ "agreement": name, } - return perror.New(errAgreementAlreadyExists, fields) + return serror.New(errAgreementAlreadyExists, fields) } msg := &agreementMsg{ LTime: t.clock.Increment(), @@ -648,12 +648,12 @@ func (t *tribe) AddAgreement(name string) perror.SnapError { return nil } -func (t *tribe) RemoveAgreement(name string) perror.SnapError { +func (t *tribe) RemoveAgreement(name string) serror.SnapError { if _, ok := t.agreements[name]; !ok { fields := log.Fields{ "Agreement": name, } - return perror.New(errAgreementDoesNotExist, fields) + return serror.New(errAgreementDoesNotExist, fields) } msg := &agreementMsg{ LTime: t.clock.Increment(), @@ -1294,7 +1294,7 @@ func (t *tribe) registerQueryResponse(timeout time.Duration, resp *taskStateQuer }) } -func (t *tribe) joinAgreement(msg *agreementMsg) perror.SnapError { +func (t *tribe) joinAgreement(msg *agreementMsg) serror.SnapError { if err := t.canJoinAgreement(msg.Agreement(), msg.MemberName); err != nil { return err } @@ -1343,7 +1343,7 @@ func (t *tribe) joinAgreement(msg *agreementMsg) perror.SnapError { return nil } -func (t *tribe) leaveAgreement(msg *agreementMsg) perror.SnapError { +func (t *tribe) leaveAgreement(msg *agreementMsg) serror.SnapError { if err := t.canLeaveAgreement(msg.Agreement(), msg.MemberName); err != nil { return err } @@ -1357,50 +1357,50 @@ func (t *tribe) leaveAgreement(msg *agreementMsg) perror.SnapError { return nil } -func (t *tribe) canLeaveAgreement(agreementName, memberName string) perror.SnapError { +func (t *tribe) canLeaveAgreement(agreementName, memberName string) serror.SnapError { fields := log.Fields{ "member-name": memberName, "agreement": agreementName, } if _, ok := t.agreements[agreementName]; !ok { t.logger.WithFields(fields).Debugln(errAgreementDoesNotExist) - return perror.New(errAgreementDoesNotExist, fields) + return serror.New(errAgreementDoesNotExist, fields) } m, ok := t.members[memberName] if !ok { t.logger.WithFields(fields).Debugln(errUnknownMember) - return perror.New(errUnknownMember, fields) + return serror.New(errUnknownMember, fields) } if m.PluginAgreement == nil { t.logger.WithFields(fields).Debugln(errNotAMember) - return perror.New(errNotAMember, fields) + return serror.New(errNotAMember, fields) } return nil } -func (t *tribe) canJoinAgreement(agreementName, memberName string) perror.SnapError { +func (t *tribe) canJoinAgreement(agreementName, memberName string) serror.SnapError { fields := log.Fields{ "member-name": memberName, "agreement": agreementName, } if _, ok := t.agreements[agreementName]; !ok { t.logger.WithFields(fields).Debugln(errAgreementDoesNotExist) - return perror.New(errAgreementDoesNotExist, fields) + return serror.New(errAgreementDoesNotExist, fields) } m, ok := t.members[memberName] if !ok { t.logger.WithFields(fields).Debugln(errUnknownMember) - return perror.New(errUnknownMember, fields) + return serror.New(errUnknownMember, fields) } if m.PluginAgreement != nil && len(m.PluginAgreement.Plugins) > 0 { t.logger.WithFields(fields).Debugln(errAlreadyMemberOfPluginAgreement) - return perror.New(errAlreadyMemberOfPluginAgreement, fields) + return serror.New(errAlreadyMemberOfPluginAgreement, fields) } return nil } -func (t *tribe) canAddTask(task agreement.Task, agreementName string) perror.SnapError { +func (t *tribe) canAddTask(task agreement.Task, agreementName string) serror.SnapError { fields := log.Fields{ "agreement": agreementName, "task-id": task.ID, @@ -1408,16 +1408,16 @@ func (t *tribe) canAddTask(task agreement.Task, agreementName string) perror.Sna a, ok := t.agreements[agreementName] if !ok { t.logger.WithFields(fields).Debugln(errAgreementDoesNotExist) - return perror.New(errAgreementDoesNotExist, fields) + return serror.New(errAgreementDoesNotExist, fields) } if ok, _ := a.TaskAgreement.Tasks.Contains(task); ok { t.logger.WithFields(fields).Debugln(errTaskAlreadyExists) - return perror.New(errTaskAlreadyExists, fields) + return serror.New(errTaskAlreadyExists, fields) } return nil } -func (t *tribe) canStartStopRemoveTask(task agreement.Task, agreementName string) perror.SnapError { +func (t *tribe) canStartStopRemoveTask(task agreement.Task, agreementName string) serror.SnapError { fields := log.Fields{ "agreement": agreementName, "task-id": task.ID, @@ -1425,11 +1425,11 @@ func (t *tribe) canStartStopRemoveTask(task agreement.Task, agreementName string a, ok := t.agreements[agreementName] if !ok { t.logger.WithFields(fields).Debugln(errAgreementDoesNotExist) - return perror.New(errAgreementDoesNotExist, fields) + return serror.New(errAgreementDoesNotExist, fields) } if ok, _ := a.TaskAgreement.Tasks.Contains(task); !ok { t.logger.WithFields(fields).Debugln(errTaskDoesNotExist) - return perror.New(errTaskDoesNotExist, fields) + return serror.New(errTaskDoesNotExist, fields) } return nil } diff --git a/mgmt/tribe/tribe_test.go b/mgmt/tribe/tribe_test.go index bf50e0453..fcfd42d76 100644 --- a/mgmt/tribe/tribe_test.go +++ b/mgmt/tribe/tribe_test.go @@ -30,7 +30,7 @@ import ( log "github.com/Sirupsen/logrus" "github.com/intelsdi-x/snap/core" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/mgmt/tribe/agreement" "github.com/intelsdi-x/snap/pkg/schedule" "github.com/intelsdi-x/snap/scheduler/wmap" @@ -45,8 +45,8 @@ func (m *mockTaskManager) GetTask(id string) (core.Task, error) { return &mockTa func (m *mockTaskManager) CreateTaskTribe(sch schedule.Schedule, wfMap *wmap.WorkflowMap, startOnCreate bool, opts ...core.TaskOption) (core.Task, core.TaskErrors) { return nil, nil } -func (m *mockTaskManager) StopTaskTribe(id string) []perror.SnapError { return nil } -func (m *mockTaskManager) StartTaskTribe(id string) []perror.SnapError { return nil } +func (m *mockTaskManager) StopTaskTribe(id string) []serror.SnapError { return nil } +func (m *mockTaskManager) StartTaskTribe(id string) []serror.SnapError { return nil } func (m *mockTaskManager) RemoveTaskTribe(id string) error { return nil } type mockTask struct{} @@ -123,12 +123,12 @@ func TestTribeFullStateSync(t *testing.T) { wg.Wait() Convey("agreements are added", func() { t := tribes[rand.Intn(len(tribes))] - perr := t.AddAgreement(agreement1) - So(perr, ShouldBeNil) + serr := t.AddAgreement(agreement1) + So(serr, ShouldBeNil) err := t.AddPlugin(agreement1, plugin1) So(err, ShouldBeNil) - perr = t.AddTask(agreement1, task1) - So(perr, ShouldBeNil) + serr = t.AddTask(agreement1, task1) + So(serr, ShouldBeNil) So(len(t.agreements), ShouldEqual, 1) Convey("the state is consistent across the tribe", func() { wg = sync.WaitGroup{} diff --git a/mgmt/tribe/worker/worker.go b/mgmt/tribe/worker/worker.go index 35dc1f762..4c3b77ad8 100644 --- a/mgmt/tribe/worker/worker.go +++ b/mgmt/tribe/worker/worker.go @@ -34,7 +34,7 @@ import ( log "github.com/Sirupsen/logrus" "github.com/intelsdi-x/snap/core" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/mgmt/rest/client" "github.com/intelsdi-x/snap/mgmt/rest/request" "github.com/intelsdi-x/snap/pkg/schedule" @@ -103,16 +103,16 @@ type Task struct { } type ManagesPlugins interface { - Load(*core.RequestedPlugin) (core.CatalogedPlugin, perror.SnapError) - Unload(plugin core.Plugin) (core.CatalogedPlugin, perror.SnapError) + Load(*core.RequestedPlugin) (core.CatalogedPlugin, serror.SnapError) + Unload(plugin core.Plugin) (core.CatalogedPlugin, serror.SnapError) PluginCatalog() core.PluginCatalog } type ManagesTasks interface { GetTask(id string) (core.Task, error) CreateTaskTribe(sch schedule.Schedule, wfMap *wmap.WorkflowMap, startOnCreate bool, opts ...core.TaskOption) (core.Task, core.TaskErrors) - StopTaskTribe(id string) []perror.SnapError - StartTaskTribe(id string) []perror.SnapError + StopTaskTribe(id string) []serror.SnapError + StartTaskTribe(id string) []serror.SnapError RemoveTaskTribe(id string) error } diff --git a/mgmt/tribe/worker/worker_test.go b/mgmt/tribe/worker/worker_test.go index a95d5b4ab..98d5bc5a9 100644 --- a/mgmt/tribe/worker/worker_test.go +++ b/mgmt/tribe/worker/worker_test.go @@ -28,16 +28,16 @@ package worker // . "github.com/smartystreets/goconvey/convey" // // "github.com/intelsdi-x/snap/core" -// "github.com/intelsdi-x/snap/core/perror" +// "github.com/intelsdi-x/snap/core/serror" // ) // // type mockPluginManager struct{} // -// func (m *mockPluginManager) Load(path string) (core.CatalogedPlugin, perror.SnapError) { +// func (m *mockPluginManager) Load(path string) (core.CatalogedPlugin, serror.SnapError) { // return nil, nil // } // -// func (m *mockPluginManager) Unload(plugin core.Plugin) (core.CatalogedPlugin, perror.SnapError) { +// func (m *mockPluginManager) Unload(plugin core.Plugin) (core.CatalogedPlugin, serror.SnapError) { // return nil, nil // } // diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index e66524c65..77fd91c77 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -30,8 +30,8 @@ import ( "github.com/intelsdi-x/snap/core" "github.com/intelsdi-x/snap/core/ctypes" - "github.com/intelsdi-x/snap/core/perror" "github.com/intelsdi-x/snap/core/scheduler_event" + "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/pkg/schedule" "github.com/intelsdi-x/snap/scheduler/wmap" ) @@ -59,9 +59,9 @@ type managesMetrics interface { publishesMetrics processesMetrics managesPluginContentTypes - ValidateDeps([]core.Metric, []core.SubscribedPlugin) []perror.SnapError - SubscribeDeps(string, []core.Metric, []core.Plugin) []perror.SnapError - UnsubscribeDeps(string, []core.Metric, []core.Plugin) []perror.SnapError + ValidateDeps([]core.Metric, []core.SubscribedPlugin) []serror.SnapError + SubscribeDeps(string, []core.Metric, []core.Plugin) []serror.SnapError + UnsubscribeDeps(string, []core.Metric, []core.Plugin) []serror.SnapError } // ManagesPluginContentTypes is an interface to a plugin manager that can tell us what content accept and returns are supported. @@ -118,10 +118,10 @@ func New(opts ...workManagerOption) *scheduler { } type taskErrors struct { - errs []perror.SnapError + errs []serror.SnapError } -func (t *taskErrors) Errors() []perror.SnapError { +func (t *taskErrors) Errors() []serror.SnapError { return t.errs } @@ -149,12 +149,12 @@ func (s *scheduler) createTask(sch schedule.Schedule, wfMap *wmap.WorkflowMap, s }) // Create a container for task errors te := &taskErrors{ - errs: make([]perror.SnapError, 0), + errs: make([]serror.SnapError, 0), } // Return error if we are not started. if s.state != schedulerStarted { - te.errs = append(te.errs, perror.New(ErrSchedulerNotStarted)) + te.errs = append(te.errs, serror.New(ErrSchedulerNotStarted)) f := buildErrorsLog(te.Errors(), logger) f.Error("scheduler not started") return nil, te @@ -162,7 +162,7 @@ func (s *scheduler) createTask(sch schedule.Schedule, wfMap *wmap.WorkflowMap, s // Ensure the schedule is valid at this point and time. if err := sch.Validate(); err != nil { - te.errs = append(te.errs, perror.New(err)) + te.errs = append(te.errs, serror.New(err)) f := buildErrorsLog(te.Errors(), logger) f.Error("schedule passed not valid") return nil, te @@ -171,7 +171,7 @@ func (s *scheduler) createTask(sch schedule.Schedule, wfMap *wmap.WorkflowMap, s // Generate a workflow from the workflow map wf, err := wmapToWorkflow(wfMap) if err != nil { - te.errs = append(te.errs, perror.New(err)) + te.errs = append(te.errs, serror.New(err)) f := buildErrorsLog(te.Errors(), logger) f.Error(ErrSchedulerNotStarted.Error()) return nil, te @@ -193,7 +193,7 @@ func (s *scheduler) createTask(sch schedule.Schedule, wfMap *wmap.WorkflowMap, s // Add task to taskCollection if err := s.tasks.add(task); err != nil { - te.errs = append(te.errs, perror.New(err)) + te.errs = append(te.errs, serror.New(err)) f := buildErrorsLog(te.Errors(), logger) f.Error("errors during task creation") return nil, te @@ -280,15 +280,15 @@ func (s *scheduler) GetTask(id string) (core.Task, error) { } // StartTask provided a task id a task is started -func (s *scheduler) StartTask(id string) []perror.SnapError { +func (s *scheduler) StartTask(id string) []serror.SnapError { return s.startTask(id, "user") } -func (s *scheduler) StartTaskTribe(id string) []perror.SnapError { +func (s *scheduler) StartTaskTribe(id string) []serror.SnapError { return s.startTask(id, "tribe") } -func (s *scheduler) startTask(id, source string) []perror.SnapError { +func (s *scheduler) startTask(id, source string) []serror.SnapError { logger := s.logger.WithFields(log.Fields{ "_block": "start-task", "source": source, @@ -300,8 +300,8 @@ func (s *scheduler) startTask(id, source string) []perror.SnapError { "_error": ErrTaskNotFound, "task-id": id, }).Error("error starting task") - return []perror.SnapError{ - perror.New(err), + return []serror.SnapError{ + serror.New(err), } } @@ -310,8 +310,8 @@ func (s *scheduler) startTask(id, source string) []perror.SnapError { "task-id": t.ID(), "task-state": t.State(), }).Info("task is already running") - return []perror.SnapError{ - perror.New(ErrTaskAlreadyRunning), + return []serror.SnapError{ + serror.New(ErrTaskAlreadyRunning), } } @@ -336,15 +336,15 @@ func (s *scheduler) startTask(id, source string) []perror.SnapError { } // StopTask provided a task id a task is stopped -func (s *scheduler) StopTask(id string) []perror.SnapError { +func (s *scheduler) StopTask(id string) []serror.SnapError { return s.stopTask(id, "user") } -func (s *scheduler) StopTaskTribe(id string) []perror.SnapError { +func (s *scheduler) StopTaskTribe(id string) []serror.SnapError { return s.stopTask(id, "tribe") } -func (s *scheduler) stopTask(id, source string) []perror.SnapError { +func (s *scheduler) stopTask(id, source string) []serror.SnapError { logger := s.logger.WithFields(log.Fields{ "_block": "stop-task", "source": source, @@ -355,8 +355,8 @@ func (s *scheduler) stopTask(id, source string) []perror.SnapError { "_error": err.Error(), "task-id": id, }).Error("error stopping task") - return []perror.SnapError{ - perror.New(err), + return []serror.SnapError{ + serror.New(err), } } @@ -365,8 +365,8 @@ func (s *scheduler) stopTask(id, source string) []perror.SnapError { "task-id": t.ID(), "task-state": t.State(), }).Info("task is already stopped") - return []perror.SnapError{ - perror.New(ErrTaskAlreadyStopped), + return []serror.SnapError{ + serror.New(ErrTaskAlreadyStopped), } } @@ -573,7 +573,7 @@ func returnCorePlugin(plugins []core.SubscribedPlugin) []core.Plugin { return cps } -func buildErrorsLog(errs []perror.SnapError, logger *log.Entry) *log.Entry { +func buildErrorsLog(errs []serror.SnapError, logger *log.Entry) *log.Entry { for i, e := range errs { logger = logger.WithField(fmt.Sprintf("%s[%d]", "error", i), e.Error()) } diff --git a/scheduler/scheduler_test.go b/scheduler/scheduler_test.go index 641a421b1..31d5a693d 100644 --- a/scheduler/scheduler_test.go +++ b/scheduler/scheduler_test.go @@ -31,7 +31,7 @@ import ( "github.com/intelsdi-x/snap/core" "github.com/intelsdi-x/snap/core/cdata" "github.com/intelsdi-x/snap/core/ctypes" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/pkg/schedule" "github.com/intelsdi-x/snap/scheduler/wmap" ) @@ -91,21 +91,21 @@ func (m *mockMetricManager) ProcessMetrics(contentType string, content []byte, p return "", nil, nil } -func (m *mockMetricManager) ValidateDeps(mts []core.Metric, prs []core.SubscribedPlugin) []perror.SnapError { +func (m *mockMetricManager) ValidateDeps(mts []core.Metric, prs []core.SubscribedPlugin) []serror.SnapError { if m.failValidatingMetrics { - return []perror.SnapError{ - perror.New(errors.New("metric validation error")), + return []serror.SnapError{ + serror.New(errors.New("metric validation error")), } } return nil } -func (m *mockMetricManager) SubscribeDeps(taskId string, mts []core.Metric, prs []core.Plugin) []perror.SnapError { - return []perror.SnapError{ - perror.New(errors.New("metric validation error")), +func (m *mockMetricManager) SubscribeDeps(taskId string, mts []core.Metric, prs []core.Plugin) []serror.SnapError { + return []serror.SnapError{ + serror.New(errors.New("metric validation error")), } } -func (m *mockMetricManager) UnsubscribeDeps(taskId string, mts []core.Metric, prs []core.Plugin) []perror.SnapError { +func (m *mockMetricManager) UnsubscribeDeps(taskId string, mts []core.Metric, prs []core.Plugin) []serror.SnapError { return nil } @@ -219,7 +219,7 @@ func TestScheduler(t *testing.T) { So(err, ShouldNotBeNil) fmt.Printf("%d", len(err.Errors())) So(len(err.Errors()), ShouldBeGreaterThan, 0) - So(err.Errors()[0], ShouldResemble, perror.New(errors.New("metric validation error"))) + So(err.Errors()[0], ShouldResemble, serror.New(errors.New("metric validation error"))) }) @@ -248,7 +248,7 @@ func TestScheduler(t *testing.T) { _, err := s1.CreateTask(schedule.NewSimpleSchedule(time.Second*1), w, false) So(err, ShouldNotBeNil) So(len(err.Errors()), ShouldBeGreaterThan, 0) - So(err.Errors()[0], ShouldResemble, perror.New(ErrSchedulerNotStarted)) + So(err.Errors()[0], ShouldResemble, serror.New(ErrSchedulerNotStarted)) s1.metricManager = c s1.Start() _, err1 := s1.CreateTask(schedule.NewSimpleSchedule(time.Second*0), w, false) diff --git a/snapd.go b/snapd.go index 1d14cf6f9..73bf068dc 100644 --- a/snapd.go +++ b/snapd.go @@ -37,7 +37,7 @@ import ( "github.com/intelsdi-x/snap/control" "github.com/intelsdi-x/snap/core" - "github.com/intelsdi-x/snap/core/perror" + "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/mgmt/rest" "github.com/intelsdi-x/snap/mgmt/tribe" "github.com/intelsdi-x/snap/mgmt/tribe/agreement" @@ -132,12 +132,12 @@ type coreModule interface { } type managesTribe interface { - GetAgreement(name string) (*agreement.Agreement, perror.SnapError) + GetAgreement(name string) (*agreement.Agreement, serror.SnapError) GetAgreements() map[string]*agreement.Agreement - AddAgreement(name string) perror.SnapError - RemoveAgreement(name string) perror.SnapError - JoinAgreement(agreementName, memberName string) perror.SnapError - LeaveAgreement(agreementName, memberName string) perror.SnapError + 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 }