From cae9564f298819e9e48038191bdfa7df5be79cbf Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Mon, 13 Apr 2020 00:17:15 +0800 Subject: [PATCH] update vendor --- go.mod | 6 +-- go.sum | 10 +++-- vendor/modules.txt | 6 +-- vendor/yunion.io/x/jsonutils/consts.go | 19 ++++++++ vendor/yunion.io/x/jsonutils/dict.go | 43 +++++++++++++++++++ vendor/yunion.io/x/jsonutils/marshal.go | 39 +++++++++++++++++ vendor/yunion.io/x/jsonutils/unmarshal.go | 2 +- vendor/yunion.io/x/log/log.go | 15 +++++-- vendor/yunion.io/x/pkg/errors/errors.go | 4 ++ .../x/pkg/util/reflectutils/jsonfield.go | 30 +++++++++++-- 10 files changed, 156 insertions(+), 18 deletions(-) create mode 100644 vendor/yunion.io/x/jsonutils/consts.go diff --git a/go.mod b/go.mod index e7454c0f5b..bfe09c904f 100644 --- a/go.mod +++ b/go.mod @@ -129,9 +129,9 @@ require ( k8s.io/cluster-bootstrap v0.17.3 k8s.io/kubernetes v1.16.0 yunion.io/x/executor v0.0.0-20200227030256-a18417815e74 - yunion.io/x/jsonutils v0.0.0-20200303051356-aa609aba0cda - yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d - yunion.io/x/pkg v0.0.0-20200304112442-9dae9351325e + yunion.io/x/jsonutils v0.0.0-20200330063846-589d9924bb8b + yunion.io/x/log v0.0.0-20200313080802-57a4ce5966b3 + yunion.io/x/pkg v0.0.0-20200403115157-880d716ed624 yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e yunion.io/x/sqlchemy v0.0.0-20200312002602-1177cd8fbc57 yunion.io/x/structarg v0.0.0-20190809075558-115bed041de3 diff --git a/go.sum b/go.sum index e7881bac7e..c15caa27ee 100644 --- a/go.sum +++ b/go.sum @@ -1015,16 +1015,18 @@ vbom.ml/util v0.0.0-20160121211510-db5cfe13f5cc/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj yunion.io/x/executor v0.0.0-20200227030256-a18417815e74 h1:A15C6VdVRWvmQ9pAJHrUs9yan5qKlYH7uaRxHg1kRbk= yunion.io/x/executor v0.0.0-20200227030256-a18417815e74/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws= yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634= -yunion.io/x/jsonutils v0.0.0-20200303051356-aa609aba0cda h1:wSwQj3MDGchGYM2RAo1riYhrTz4apH+5XyBnchuDi84= -yunion.io/x/jsonutils v0.0.0-20200303051356-aa609aba0cda/go.mod h1:T7kxQJR13+t7z0TuT+Wzd7MTxBOk2H9c0pO1ONQSv90= +yunion.io/x/jsonutils v0.0.0-20200330063846-589d9924bb8b h1:mt0TOKRk76yeH0whJfmKsceXBuudXLjvoj8NKGTqpEU= +yunion.io/x/jsonutils v0.0.0-20200330063846-589d9924bb8b/go.mod h1:T7kxQJR13+t7z0TuT+Wzd7MTxBOk2H9c0pO1ONQSv90= yunion.io/x/log v0.0.0-20190514041436-04ce53b17c6b/go.mod h1:+gauLs73omeJAPlsXcevLsJLKixV+sR/E7WSYTSx1fE= yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d h1:59zrDL7Ft+hDukguJRmLr/Gdu/9V75x+yX99ovZwfaA= yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d/go.mod h1:LC6f/4FozL0iaAbnFt2eDX9jlsyo3WiOUPm03d7+U4U= +yunion.io/x/log v0.0.0-20200313080802-57a4ce5966b3 h1:5Wc5hkB8PtMudmHuzCyok960RuOa9I55imIGrigSdjs= +yunion.io/x/log v0.0.0-20200313080802-57a4ce5966b3/go.mod h1:LC6f/4FozL0iaAbnFt2eDX9jlsyo3WiOUPm03d7+U4U= yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E= yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E= yunion.io/x/pkg v0.0.0-20200302034534-fdf44d54b070/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E= -yunion.io/x/pkg v0.0.0-20200304112442-9dae9351325e h1:rBfX77+VEBVpe6Xxy2gDa4WB7qbtndWvXcrVKzleF84= -yunion.io/x/pkg v0.0.0-20200304112442-9dae9351325e/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E= +yunion.io/x/pkg v0.0.0-20200403115157-880d716ed624 h1:yPayJlTJHOP0vKY6ovliZyTwJY9RvdWEF+QDqnxt/iw= +yunion.io/x/pkg v0.0.0-20200403115157-880d716ed624/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E= yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo= yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo= yunion.io/x/sqlchemy v0.0.0-20200312002602-1177cd8fbc57 h1:KtQAuLJ00RSUVqkiRmJ1DiDABiw0U3xxXnzD3lGavaY= diff --git a/vendor/modules.txt b/vendor/modules.txt index 8dc6c633f0..fd561accf7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -924,12 +924,12 @@ sigs.k8s.io/yaml yunion.io/x/executor/apis yunion.io/x/executor/client yunion.io/x/executor/server -# yunion.io/x/jsonutils v0.0.0-20200303051356-aa609aba0cda +# yunion.io/x/jsonutils v0.0.0-20200330063846-589d9924bb8b yunion.io/x/jsonutils -# yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d +# yunion.io/x/log v0.0.0-20200313080802-57a4ce5966b3 yunion.io/x/log yunion.io/x/log/hooks -# yunion.io/x/pkg v0.0.0-20200304112442-9dae9351325e +# yunion.io/x/pkg v0.0.0-20200403115157-880d716ed624 yunion.io/x/pkg/errors yunion.io/x/pkg/gotypes yunion.io/x/pkg/prettytable diff --git a/vendor/yunion.io/x/jsonutils/consts.go b/vendor/yunion.io/x/jsonutils/consts.go new file mode 100644 index 0000000000..f5f2721bed --- /dev/null +++ b/vendor/yunion.io/x/jsonutils/consts.go @@ -0,0 +1,19 @@ +// Copyright 2019 Yunion +// +// 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 jsonutils + +const ( + TAG_DEPRECATED_BY = "deprecated-by" +) diff --git a/vendor/yunion.io/x/jsonutils/dict.go b/vendor/yunion.io/x/jsonutils/dict.go index 87db0ca23b..9f15f3c8c3 100644 --- a/vendor/yunion.io/x/jsonutils/dict.go +++ b/vendor/yunion.io/x/jsonutils/dict.go @@ -35,3 +35,46 @@ func (dict *JSONDict) UpdateDefault(json JSONObject) { } } } + +func Diff(a, b *JSONDict) (aNoB, aDiffB, aAndB, bNoA *JSONDict) { + keysA := a.SortedKeys() + keysB := b.SortedKeys() + aNoB = NewDict() + aDiffB = NewDict() + aAndB = NewDict() + bNoA = NewDict() + + i := 0 + j := 0 + for i < len(keysA) || j < len(keysB) { + if i < len(keysA) && j < len(keysB) { + keyA := keysA[i] + keyB := keysB[j] + if keyA > keyB { + aNoB.data[keyA] = a.data[keyA] + i += 1 + } else if keyA < keyB { + bNoA.data[keyB] = b.data[keyB] + j += 1 + } else { + valA := a.data[keysA[i]].String() + valB := b.data[keysB[i]].String() + if valA != valB { + aDiffB.data[keyA] = NewArray(a.data[keyA], b.data[keyB]) + } else { + aAndB.data[keyA] = a.data[keyA] + } + i += 1 + j += 1 + } + } else if i < len(keysA) { + aNoB.data[keysA[i]] = a.data[keysA[i]] + i = i + 1 + } else if j < len(keysB) { + bNoA.data[keysB[j]] = b.data[keysB[j]] + j = j + 1 + } + } + + return +} diff --git a/vendor/yunion.io/x/jsonutils/marshal.go b/vendor/yunion.io/x/jsonutils/marshal.go index 3392a8f018..e6bc0aeaeb 100644 --- a/vendor/yunion.io/x/jsonutils/marshal.go +++ b/vendor/yunion.io/x/jsonutils/marshal.go @@ -83,21 +83,60 @@ func marshalStruct(val reflect.Value, info *reflectutils.SStructFieldInfo) JSONO } } +func findValueByKey(pairs []JSONPair, key string) JSONObject { + for i := range pairs { + if pairs[i].key == key { + return pairs[i].val + } + } + return nil +} + func struct2JSONPairs(val reflect.Value) []JSONPair { fields := reflectutils.FetchStructFieldValueSet(val) objPairs := make([]JSONPair, 0, len(fields)) + depFields := make(map[string]string) for i := 0; i < len(fields); i += 1 { jsonInfo := fields[i].Info if jsonInfo.Ignore { continue } key := jsonInfo.MarshalName() + if deprecatedBy, ok := fields[i].Info.Tags[TAG_DEPRECATED_BY]; ok { + depFields[key] = deprecatedBy + continue + } val := marshalValue(fields[i].Value, jsonInfo) if val != nil && val != JSONNull { objPair := JSONPair{key: key, val: val} objPairs = append(objPairs, objPair) } } + depPairs := make([]JSONPair, 0, len(depFields)) + for depKey, key := range depFields { + findLoop := false + for { + if okey, ok := depFields[key]; ok { + if okey == depKey { + // loop detected + findLoop = true + break + } + key = okey + } else { + break + } + } + if findLoop { + continue + } + val := findValueByKey(objPairs, key) + if val != nil { + objPair := JSONPair{key: depKey, val: val} + depPairs = append(depPairs, objPair) + } + } + objPairs = append(objPairs, depPairs...) return objPairs } diff --git a/vendor/yunion.io/x/jsonutils/unmarshal.go b/vendor/yunion.io/x/jsonutils/unmarshal.go index 7739088a02..8c4911ea46 100644 --- a/vendor/yunion.io/x/jsonutils/unmarshal.go +++ b/vendor/yunion.io/x/jsonutils/unmarshal.go @@ -539,7 +539,7 @@ func setStructFieldAt(key string, v JSONObject, fieldValues reflectutils.SStruct if err != nil { return errors.Wrap(err, "JSONDict.unmarshalStruct") } - depInfo, ok := fieldValues[index].Info.Tags["deprecated-by"] + depInfo, ok := fieldValues[index].Info.Tags[TAG_DEPRECATED_BY] if ok { err := setStructFieldAt(depInfo, v, fieldValues, visited) if err != nil { diff --git a/vendor/yunion.io/x/log/log.go b/vendor/yunion.io/x/log/log.go index 7e51dabc4c..a26d3e439c 100644 --- a/vendor/yunion.io/x/log/log.go +++ b/vendor/yunion.io/x/log/log.go @@ -149,9 +149,18 @@ func DisableColors() { } func AddHookFormatter(logger *logrus.Logger) { - pcs := make([]uintptr, 2) - runtime.Callers(0, pcs) - logrusPackage := hooks.GetPackageName(runtime.FuncForPC(pcs[1]).Name()) + pcs := make([]uintptr, 1) + npcs := runtime.Callers(1, pcs) + frames := runtime.CallersFrames(pcs[:npcs]) + var myName string + for { + f, more := frames.Next() + myName = f.Function + if !more { + break + } + } + logrusPackage := hooks.GetPackageName(myName) logger.Hooks.Add(&hooks.CallerHook{logrusPackage}) logger.Formatter = &TextFormatter{ TimestampFormat: "060102 15:04:05", diff --git a/vendor/yunion.io/x/pkg/errors/errors.go b/vendor/yunion.io/x/pkg/errors/errors.go index 108cbf6db7..9a6ada341a 100644 --- a/vendor/yunion.io/x/pkg/errors/errors.go +++ b/vendor/yunion.io/x/pkg/errors/errors.go @@ -33,3 +33,7 @@ func Wrapf(err error, format string, args ...interface{}) error { func Cause(err error) error { return errors.Cause(err) } + +func Errorf(format string, args ...interface{}) error { + return errors.Errorf(format, args...) +} diff --git a/vendor/yunion.io/x/pkg/util/reflectutils/jsonfield.go b/vendor/yunion.io/x/pkg/util/reflectutils/jsonfield.go index 8871c1431f..9b70f0d4a2 100644 --- a/vendor/yunion.io/x/pkg/util/reflectutils/jsonfield.go +++ b/vendor/yunion.io/x/pkg/util/reflectutils/jsonfield.go @@ -44,6 +44,10 @@ type SStructFieldInfo struct { Tags map[string]string } +func (s *SStructFieldInfo) updateTags(k, v string) { + s.Tags[k] = v +} + func (s SStructFieldInfo) deepCopy() *SStructFieldInfo { scopy := SStructFieldInfo{ Ignore: s.Ignore, @@ -134,11 +138,11 @@ type SStructFieldValue struct { type SStructFieldValueSet []SStructFieldValue func FetchStructFieldValueSet(dataValue reflect.Value) SStructFieldValueSet { - return fetchStructFieldValueSet(dataValue, false) + return fetchStructFieldValueSet(dataValue, false, nil) } func FetchStructFieldValueSetForWrite(dataValue reflect.Value) SStructFieldValueSet { - return fetchStructFieldValueSet(dataValue, true) + return fetchStructFieldValueSet(dataValue, true, nil) } type sStructFieldInfoMap map[string]SStructFieldInfo @@ -182,7 +186,7 @@ func fetchStructFieldInfos(dataType reflect.Type) sStructFieldInfoMap { return smap } -func fetchStructFieldValueSet(dataValue reflect.Value, allocatePtr bool) SStructFieldValueSet { +func fetchStructFieldValueSet(dataValue reflect.Value, allocatePtr bool, tags map[string]string) SStructFieldValueSet { fields := SStructFieldValueSet{} dataType := dataValue.Type() fieldInfos := fetchCacheStructFieldInfos(dataType) @@ -218,7 +222,8 @@ func fetchStructFieldValueSet(dataValue reflect.Value, allocatePtr bool) SStruct // different from how encoding/json handles struct // field of interface type. if fv.Kind() == reflect.Struct && sf.Type != gotypes.TimeType { - subfields := fetchStructFieldValueSet(fv, allocatePtr) + anonymousTags := utils.TagMap(sf.Tag) + subfields := fetchStructFieldValueSet(fv, allocatePtr, anonymousTags) fields = append(fields, subfields...) continue } @@ -231,6 +236,23 @@ func fetchStructFieldValueSet(dataValue reflect.Value, allocatePtr bool) SStruct }) } } + if len(tags) > 0 { + for i := range fields { + fieldName := fields[i].Info.MarshalName() + for k, v := range tags { + target := "" + pos := strings.Index(k, "->") + if pos > 0 { + target = k[:pos] + k = k[pos+2:] + } + if len(target) > 0 && target != fieldName { + continue + } + fields[i].Info.updateTags(k, v) + } + } + } return fields }