本文整理汇总了Golang中github.com/intelsdi-x/snap/core.Plugin类的典型用法代码示例。如果您正苦于以下问题:Golang Plugin类的具体用法?Golang Plugin怎么用?Golang Plugin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Plugin类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ToCorePluginMsg
// Convert from core.Plugin to Plugin protobuf message
func ToCorePluginMsg(pl core.Plugin) *Plugin {
return &Plugin{
TypeName: pl.TypeName(),
Name: pl.Name(),
Version: int64(pl.Version()),
}
}
开发者ID:IRCody,项目名称:snap,代码行数:8,代码来源:common.go
示例2: Unload
func (m MockManagesMetrics) Unload(plugin core.Plugin) (core.CatalogedPlugin, serror.SnapError) {
for _, pl := range pluginCatalog {
if plugin.Name() == pl.Name() &&
plugin.Version() == pl.Version() &&
plugin.TypeName() == pl.TypeName() {
return pl, nil
}
}
return nil, serror.New(errors.New("plugin not found"))
}
开发者ID:IRCody,项目名称:snap,代码行数:10,代码来源:mock_metric_manager.go
示例3: sendPluginSubscriptionEvent
func (p *pluginControl) sendPluginSubscriptionEvent(taskId string, pl core.Plugin) serror.SnapError {
pt, err := core.ToPluginType(pl.TypeName())
if err != nil {
return serror.New(err)
}
e := &control_event.PluginSubscriptionEvent{
TaskId: taskId,
PluginType: int(pt),
PluginName: pl.Name(),
PluginVersion: pl.Version(),
SubscriptionType: int(unboundSubscriptionType),
}
if pl.Version() > 0 {
e.SubscriptionType = int(boundSubscriptionType)
}
if _, err := p.eventManager.Emit(e); err != nil {
return serror.New(err)
}
return nil
}
开发者ID:gitter-badger,项目名称:snap-1,代码行数:20,代码来源:control.go
示例4: sendPluginUnsubscriptionEvent
func (p *subscriptionGroup) sendPluginUnsubscriptionEvent(taskID string,
pl core.Plugin) serror.SnapError {
pt, err := core.ToPluginType(pl.TypeName())
if err != nil {
return serror.New(err)
}
e := &control_event.PluginUnsubscriptionEvent{
TaskId: taskID,
PluginType: int(pt),
PluginName: pl.Name(),
PluginVersion: pl.Version(),
}
if _, err := p.eventManager.Emit(e); err != nil {
return serror.New(err)
}
return nil
}
开发者ID:IRCody,项目名称:snap,代码行数:17,代码来源:subscription_group.go
示例5: UnloadPlugin
// UnloadPlugin unloads a plugin from the LoadedPlugins table
func (p *pluginManager) UnloadPlugin(pl core.Plugin) (*loadedPlugin, serror.SnapError) {
plugin, err := p.loadedPlugins.get(fmt.Sprintf("%s"+core.Separator+"%s"+core.Separator+"%d", pl.TypeName(), pl.Name(), pl.Version()))
if err != nil {
se := serror.New(ErrPluginNotFound, map[string]interface{}{
"plugin-name": pl.Name(),
"plugin-version": pl.Version(),
"plugin-type": pl.TypeName(),
})
return nil, se
}
pmLogger.WithFields(log.Fields{
"_block": "unload-plugin",
"path": filepath.Base(plugin.Details.Exec),
}).Info("plugin unload called")
if plugin.State != LoadedState {
se := serror.New(ErrPluginNotInLoadedState, map[string]interface{}{
"plugin-name": plugin.Name(),
"plugin-version": plugin.Version(),
"plugin-type": pl.TypeName(),
})
return nil, se
}
// If the plugin has been uploaded via REST API
// aka, was not auto loaded from auto_discover_path
// nor loaded from tests
// then do clean up
if !plugin.Details.IsAutoLoaded {
pmLogger.WithFields(log.Fields{
"plugin-type": plugin.TypeName(),
"plugin-name": plugin.Name(),
"plugin-version": plugin.Version(),
"plugin-path": plugin.Details.Path,
}).Debugf("Removing plugin")
if err := os.RemoveAll(filepath.Dir(plugin.Details.Path)); err != nil {
pmLogger.WithFields(log.Fields{
"plugin-type": plugin.TypeName(),
"plugin-name": plugin.Name(),
"plugin-version": plugin.Version(),
"plugin-path": plugin.Details.Path,
}).Error(err)
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, se
}
}
p.loadedPlugins.remove(plugin.Key())
// Remove any metrics from the catalog if this was a collector
if plugin.TypeName() == "collector" {
p.metricCatalog.RmUnloadedPluginMetrics(plugin)
}
return plugin, nil
}
开发者ID:IRCody,项目名称:snap,代码行数:63,代码来源:plugin_manager.go
示例6: UnloadPlugin
// UnloadPlugin unloads a plugin from the LoadedPlugins table
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 {
se := serror.New(ErrPluginNotFound, map[string]interface{}{
"plugin-name": pl.Name(),
"plugin-version": pl.Version(),
"plugin-type": pl.TypeName(),
})
return nil, se
}
if plugin.State != LoadedState {
se := serror.New(ErrPluginNotInLoadedState, map[string]interface{}{
"plugin-name": plugin.Name(),
"plugin-version": plugin.Version(),
"plugin-type": pl.TypeName(),
})
return nil, se
}
// If the plugin was loaded from os.TempDir() clean up
if strings.Contains(plugin.Details.Path, os.TempDir()) {
pmLogger.WithFields(log.Fields{
"plugin-type": plugin.TypeName(),
"plugin-name": plugin.Name(),
"plugin-version": plugin.Version(),
"plugin-path": plugin.Details.Path,
}).Debugf("Removing plugin")
if err := os.RemoveAll(filepath.Dir(plugin.Details.Path)); err != nil {
pmLogger.WithFields(log.Fields{
"plugin-type": plugin.TypeName(),
"plugin-name": plugin.Name(),
"plugin-version": plugin.Version(),
"plugin-path": plugin.Details.Path,
}).Error(err)
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, se
}
}
p.loadedPlugins.remove(plugin.Key())
// Remove any metrics from the catalog if this was a collector
if plugin.TypeName() == "collector" {
p.metricCatalog.RmUnloadedPluginMetrics(plugin)
}
return plugin, nil
}
开发者ID:mtanda,项目名称:snap,代码行数:57,代码来源:plugin_manager.go
示例7: loadPlugin
func (w worker) loadPlugin(plugin core.Plugin) error {
logger := w.logger.WithFields(log.Fields{
"plugin-name": plugin.Name(),
"plugin-version": plugin.Version(),
"plugin-type": plugin.TypeName(),
"_block": "load-plugin",
})
if w.isPluginLoaded(plugin.Name(), plugin.TypeName(), plugin.Version()) {
return nil
}
members, err := w.memberManager.GetPluginAgreementMembers()
if err != nil {
logger.Error(err)
return err
}
for _, member := range shuffle(members) {
url := fmt.Sprintf("%s://%s:%s/v1/plugins/%s/%s/%d?download=true", member.GetRestProto(), member.GetAddr(), member.GetRestPort(), plugin.TypeName(), plugin.Name(), plugin.Version())
c, err := client.New(url, "v1", member.GetRestInsecureSkipVerify(), client.Password(w.memberManager.GetRequestPassword()))
if err != nil {
logger.WithFields(log.Fields{
"err": err,
"url": url,
}).Info("unable to create client")
continue
}
resp, err := c.TribeRequest()
if err != nil {
logger.WithFields(log.Fields{
"err": err,
"url": url,
}).Info("plugin not found")
continue
}
if resp.StatusCode == 200 {
if resp.Header.Get("Content-Type") != "application/x-gzip" {
logger.WithField("content-type", resp.Header.Get("Content-Type")).Error("Expected application/x-gzip")
}
dir, err := ioutil.TempDir("", "")
if err != nil {
logger.Error(err)
return err
}
f, err := os.Create(path.Join(dir, fmt.Sprintf("%s-%s-%d", plugin.TypeName(), plugin.Name(), plugin.Version())))
if err != nil {
logger.Error(err)
f.Close()
return err
}
io.Copy(f, resp.Body)
f.Close()
err = os.Chmod(f.Name(), 0700)
if err != nil {
logger.Error(err)
return err
}
rp, err := core.NewRequestedPlugin(f.Name())
if err != nil {
logger.Error(err)
return err
}
_, err = w.pluginManager.Load(rp)
if err != nil {
logger.Error(err)
return err
}
if w.isPluginLoaded(plugin.Name(), plugin.TypeName(), plugin.Version()) {
return nil
}
return errors.New("failed to load plugin")
}
}
return errors.New("failed to find a member with the plugin")
}
开发者ID:Collinux,项目名称:snap,代码行数:73,代码来源:worker.go
示例8: unloadPlugin
func (w worker) unloadPlugin(plugin core.Plugin) error {
logger := w.logger.WithFields(log.Fields{
"plugin-name": plugin.Name(),
"plugin-version": plugin.Version(),
"plugin-type": plugin.TypeName(),
"_block": "unload-plugin",
})
if !w.isPluginLoaded(plugin.Name(), plugin.TypeName(), plugin.Version()) {
return nil
}
if _, err := w.pluginManager.Unload(plugin); err != nil {
logger.WithField("err", err).Info("failed to unload plugin")
return err
}
return nil
}
开发者ID:Collinux,项目名称:snap,代码行数:16,代码来源:worker.go
示例9: pluginURI
func pluginURI(host string, c core.Plugin) string {
return fmt.Sprintf("%s://%s/v1/plugins/%s/%s/%d", protocolPrefix, host, c.TypeName(), c.Name(), c.Version())
}
开发者ID:Collinux,项目名称:snap,代码行数:3,代码来源:plugin.go
注:本文中的github.com/intelsdi-x/snap/core.Plugin类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论