This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 298
/
control.go
87 lines (74 loc) · 2.56 KB
/
control.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2016 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package rpc
import (
"errors"
"strconv"
"time"
log "github.com/Sirupsen/logrus"
"github.com/intelsdi-x/snap/control/plugin/cpolicy"
"github.com/intelsdi-x/snap/core/serror"
"github.com/intelsdi-x/snap/grpc/common"
)
type Metric struct {
Namespace []string `json:"namespace"`
Version int `json:"version"`
LastAdvertisedTime time.Time `json:"last_advertised_time"`
ConfigPolicy *cpolicy.ConfigPolicyNode `json:"policy"`
}
type LoadedPlugin struct {
Name string `json:"name"`
Version int `json:"version"`
TypeName string `json:"type_name"`
IsSigned bool `json:"signed"`
Status string `json:"status"`
LoadedTimestamp time.Time `json:"timestamp"`
ConfigPolicy *cpolicy.ConfigPolicy `json:"policy,omitempty"`
}
type AvailablePlugin struct {
Name string `json:"name"`
Version int `json:"version"`
TypeName string `json:"type_name"`
Signed bool `json:"signed"`
HitCount int `json:"hit_count"`
ID uint32 `json:"id"`
LastHit time.Time `json:"last_hit"`
}
func ConvertSnapErrors(s []*common.SnapError) []serror.SnapError {
rerrs := make([]serror.SnapError, len(s))
for i, err := range s {
rerrs[i] = serror.New(errors.New(err.ErrorString), common.GetFields(err))
}
return rerrs
}
func NewErrors(errs []serror.SnapError) []*common.SnapError {
errors := make([]*common.SnapError, len(errs))
for i, err := range errs {
fields := make(map[string]string)
for k, v := range err.Fields() {
switch t := v.(type) {
case string:
fields[k] = t
case int:
fields[k] = strconv.Itoa(t)
case float64:
fields[k] = strconv.FormatFloat(t, 'f', -1, 64)
default:
log.Errorf("Unexpected type %v\n", t)
}
}
errors[i] = &common.SnapError{ErrorFields: fields, ErrorString: err.Error()}
}
return errors
}