本文整理汇总了Golang中github.com/intelsdi-x/snap/core.Plugin.Version方法的典型用法代码示例。如果您正苦于以下问题:Golang Plugin.Version方法的具体用法?Golang Plugin.Version怎么用?Golang Plugin.Version使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/intelsdi-x/snap/core.Plugin
的用法示例。
在下文中一共展示了Plugin.Version方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()),
}
}
示例2: 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 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
}
示例3: 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"))
}
示例4: sendPluginUnsubscriptionEvent
func (p *pluginControl) 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
}
示例5: 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
}
示例6: 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(strategy.UnboundSubscriptionType),
}
if pl.Version() > 0 {
e.SubscriptionType = int(strategy.BoundSubscriptionType)
}
if _, err := p.eventManager.Emit(e); err != nil {
return serror.New(err)
}
return nil
}
示例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")
}
示例8: 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())
}