Skip to content

Commit

Permalink
remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Oct 6, 2022
1 parent bb6f2c9 commit 399905a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 61 deletions.
13 changes: 3 additions & 10 deletions engine/transform.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package engine

import (
"encoding/json"

"github.com/sirupsen/logrus"

"github.com/mitchellh/mapstructure"
"github.com/projecteru2/core/engine/types"
)

// MakeVirtualizationResource .
func MakeVirtualizationResource(engineArgs map[string]interface{}) (types.VirtualizationResource, error) {
var res types.VirtualizationResource
body, err := json.Marshal(engineArgs)
if err != nil {
return res, err
}
if err = json.Unmarshal(body, &res); err != nil {
logrus.Errorf("[MakeVirtualizationResource] failed to unmarshal from engine args %v, err: %v", string(body), err)
if err := mapstructure.Decode(engineArgs, &res); err != nil {
return res, err
}
res.EngineArgs = engineArgs
Expand Down
13 changes: 2 additions & 11 deletions resources/cpumem/types/resource.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types

import (
"encoding/json"
"fmt"
"strconv"
"strings"
Expand Down Expand Up @@ -72,11 +71,7 @@ type WorkloadResourceArgs struct {

// ParseFromRawParams .
func (r *WorkloadResourceArgs) ParseFromRawParams(rawParams coretypes.RawParams) error {
body, err := json.Marshal(rawParams)
if err != nil {
return err
}
return json.Unmarshal(body, r)
return mapstructure.Decode(rawParams, r)
}

// DeepCopy .
Expand Down Expand Up @@ -466,9 +461,5 @@ type WorkloadResourceArgsMap map[string]*WorkloadResourceArgs

// ParseFromRawParamsMap .
func (w *WorkloadResourceArgsMap) ParseFromRawParamsMap(rawParamsMap map[string]coretypes.RawParams) error {
body, err := json.Marshal(rawParamsMap)
if err != nil {
return err
}
return json.Unmarshal(body, w)
return mapstructure.Decode(rawParamsMap, w)
}
23 changes: 3 additions & 20 deletions resources/volume/types/resource.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package types

import (
"encoding/json"
"sort"
"strings"
"sync"

"github.com/mitchellh/mapstructure"
coretypes "github.com/projecteru2/core/types"
coreutils "github.com/projecteru2/core/utils"

Expand Down Expand Up @@ -155,11 +155,7 @@ type WorkloadResourceArgs struct {

// ParseFromRawParams .
func (w *WorkloadResourceArgs) ParseFromRawParams(rawParams coretypes.RawParams) (err error) {
body, err := json.Marshal(rawParams)
if err != nil {
return err
}
return json.Unmarshal(body, w)
return mapstructure.Decode(rawParams, w)
}

// NodeResourceOpts .
Expand Down Expand Up @@ -242,11 +238,7 @@ type NodeResourceArgs struct {

// ParseFromRawParams .
func (n *NodeResourceArgs) ParseFromRawParams(rawParams coretypes.RawParams) error {
body, err := json.Marshal(rawParams)
if err != nil {
return err
}
return json.Unmarshal(body, n)
return mapstructure.Decode(rawParams, n)
}

// DeepCopy .
Expand Down Expand Up @@ -421,12 +413,3 @@ type EngineArgs struct {

// WorkloadResourceArgsMap .
type WorkloadResourceArgsMap map[string]*WorkloadResourceArgs

// ParseFromRawParamsMap .
func (w *WorkloadResourceArgsMap) ParseFromRawParamsMap(rawParamsMap map[string]coretypes.RawParams) error {
body, err := json.Marshal(rawParamsMap)
if err != nil {
return err
}
return json.Unmarshal(body, w)
}
7 changes: 2 additions & 5 deletions types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"

"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"

engine "github.com/projecteru2/core/engine"
Expand All @@ -23,11 +24,7 @@ type NodeMeta struct {

// DeepCopy returns a deepcopy of nodemeta
func (n NodeMeta) DeepCopy() (nn NodeMeta, err error) {
b, err := json.Marshal(n)
if err != nil {
return nn, errors.WithStack(err)
}
return nn, errors.WithStack(json.Unmarshal(b, &nn))
return nn, errors.WithStack(mapstructure.Decode(n, &nn))
}

// NodeResource for resource
Expand Down
9 changes: 0 additions & 9 deletions types/resource.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types

import (
"encoding/json"
"fmt"
"strconv"
)
Expand Down Expand Up @@ -97,14 +96,6 @@ func (r RawParams) RawParams(key string) map[string]interface{} {
return map[string]interface{}{}
}

// ConvertRawParamsToMap .
func ConvertRawParamsToMap[V any](r RawParams) map[string]V {
res := map[string]V{}
body, _ := json.Marshal(r)
_ = json.Unmarshal(body, &res)
return res
}

// NodeResourceOpts .
type NodeResourceOpts RawParams

Expand Down
6 changes: 0 additions & 6 deletions types/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,3 @@ func TestRawParams(t *testing.T) {
assert.Equal(t, r.RawParams("raw-params")["int64"], 1)
assert.Equal(t, r.IsSet("?"), false)
}

func TestCovertRawToMap(t *testing.T) {
r := RawParams{}
res := ConvertRawParamsToMap[int64](r)
assert.NotNil(t, res)
}

0 comments on commit 399905a

Please sign in to comment.