Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cluster/calcium/calcium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func NewTestCluster() *Calcium {
WALFile: filepath.Join(walDir, "core.wal.log"),
MaxConcurrency: 100000,
HAKeepaliveInterval: 16 * time.Second,
ProbeTarget: "8.8.8.8:80",
}
c.store = &storemocks.Store{}
c.source = &sourcemocks.Source{}
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c *Calcium) WatchServiceStatus(ctx context.Context) (<-chan types.ServiceS

// RegisterService writes self service address in store
func (c *Calcium) RegisterService(ctx context.Context) (unregister func(), err error) {
serviceAddress, err := utils.GetOutboundAddress(c.config.Bind)
serviceAddress, err := utils.GetOutboundAddress(c.config.Bind, c.config.ProbeTarget)
if err != nil {
log.Errorf(ctx, "[RegisterService] failed to get outbound address: %v", err)
return
Expand Down
1 change: 1 addition & 0 deletions core.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cert_path: "/etc/eru/tls" # option
max_concurrency: 100000 # optional, default 100000 for pool size
store: etcd # optional, default etcd can choose redis
sentry_dsn: "https://[email protected]/0" # optional
probe_target: "8.8.8.8:80" # optional

wal_file: core.wal # required, default core.wal
wal_open_timeout: 8s # required, default 8s
Expand Down
10 changes: 5 additions & 5 deletions engine/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import (
"strings"
"time"

"github.com/projecteru2/core/engine"
enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"
coretypes "github.com/projecteru2/core/types"

dockertypes "github.com/docker/docker/api/types"
dockercontainer "github.com/docker/docker/api/types/container"
dockernetwork "github.com/docker/docker/api/types/network"
dockerslice "github.com/docker/docker/api/types/strslice"
"github.com/docker/go-connections/nat"
"github.com/docker/go-units"

"github.com/projecteru2/core/engine"
enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"
coretypes "github.com/projecteru2/core/types"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions engine/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"net/http"
"strings"

dockerapi "github.com/docker/docker/client"

"github.com/projecteru2/core/engine"
enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"
coretypes "github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"

dockerapi "github.com/docker/docker/client"
)

const (
Expand Down
6 changes: 3 additions & 3 deletions engine/docker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"io"

enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"

dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stdcopy"

enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"
)

// ExecCreate create a exec
Expand Down
22 changes: 11 additions & 11 deletions engine/docker/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ import (
"strings"
"text/template"

corecluster "github.com/projecteru2/core/cluster"
"github.com/projecteru2/core/engine"
enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
coretypes "github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"

"github.com/docker/distribution/reference"
dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/blkiodev"
Expand All @@ -33,6 +25,14 @@ import (
"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/docker/registry"
"github.com/docker/go-units"

corecluster "github.com/projecteru2/core/cluster"
"github.com/projecteru2/core/engine"
enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
coretypes "github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
)

type fuckDockerStream struct {
Expand Down Expand Up @@ -101,7 +101,7 @@ func makeMountPaths(opts *enginetypes.VirtualizationCreateOptions) ([]string, ma
return binds, volumes
}

func makeResourceSetting(cpu float64, memory int64, cpuMap map[string]int64, numaNode string, iopsOptions map[string]string, remap bool) dockercontainer.Resources {
func makeResourceSetting(cpu float64, memory int64, cpuMap map[string]int64, numaNode string, IOPSOptions map[string]string, remap bool) dockercontainer.Resources {
resource := dockercontainer.Resources{}

resource.CPUQuota = 0
Expand Down Expand Up @@ -140,9 +140,9 @@ func makeResourceSetting(cpu float64, memory int64, cpuMap map[string]int64, num
resource.MemoryReservation = int64(units.MiB * 4)
}

if len(iopsOptions) > 0 {
if len(IOPSOptions) > 0 {
var readIOPSDevices, writeIOPSDevices, readBPSDevices, writeBPSDevices []*blkiodev.ThrottleDevice
for device, options := range iopsOptions {
for device, options := range IOPSOptions {
parts := strings.Split(options, ":")
for len(parts) < 4 {
parts = append(parts, "0")
Expand Down
8 changes: 4 additions & 4 deletions engine/docker/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ package docker
import (
"bytes"
"context"
"io"
"io/ioutil"
"os"
"strings"
"testing"

coreutils "github.com/projecteru2/core/utils"

"github.com/stretchr/testify/assert"

coreutils "github.com/projecteru2/core/utils"
)

func TestCreateTarStream(t *testing.T) {
buff := bytes.NewBufferString("test")
rc := io.NopCloser(buff)
rc := ioutil.NopCloser(buff)
fname, err := coreutils.TempFile(rc)
assert.NoError(t, err)
_, err = CreateTarStream(fname)
Expand Down
4 changes: 2 additions & 2 deletions engine/docker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"io"

enginetypes "github.com/projecteru2/core/engine/types"

dockertypes "github.com/docker/docker/api/types"
dockerfilters "github.com/docker/docker/api/types/filters"

enginetypes "github.com/projecteru2/core/engine/types"
)

// ImageList list image
Expand Down
6 changes: 3 additions & 3 deletions engine/docker/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"net"

enginetypes "github.com/projecteru2/core/engine/types"
coretypes "github.com/projecteru2/core/types"

dockertypes "github.com/docker/docker/api/types"
dockerfilters "github.com/docker/docker/api/types/filters"
dockernetwork "github.com/docker/docker/api/types/network"

enginetypes "github.com/projecteru2/core/engine/types"
coretypes "github.com/projecteru2/core/types"
)

// NetworkConnect connect to a network
Expand Down
62 changes: 31 additions & 31 deletions engine/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,6 @@ var (
engineCache *EngineCache
)

func getEngineCacheKey(endpoint, ca, cert, key string) string {
return fmt.Sprintf("%v-%v", endpoint, utils.SHA256(fmt.Sprintf(":%v:%v:%v", ca, cert, key))[:8])
}

type engineParams struct {
endpoint string
ca string
cert string
key string
}

func (ep engineParams) getCacheKey() string {
return getEngineCacheKey(ep.endpoint, ep.ca, ep.cert, ep.key)
}

// EngineCache .
type EngineCache struct {
cache *utils.EngineCache
Expand Down Expand Up @@ -145,13 +130,6 @@ func (e *EngineCache) CheckAlive(ctx context.Context) {
}
}

func validateEngine(ctx context.Context, engine engine.API, timeout time.Duration) (err error) {
utils.WithTimeout(ctx, timeout, func(ctx context.Context) {
err = engine.Ping(ctx)
})
return err
}

// GetEngineFromCache .
func GetEngineFromCache(endpoint, ca, cert, key string) engine.API {
return engineCache.Get(getEngineCacheKey(endpoint, ca, cert, key))
Expand Down Expand Up @@ -190,6 +168,37 @@ func GetEngine(ctx context.Context, config types.Config, nodename, endpoint, ca,
return newEngine(ctx, config, nodename, endpoint, ca, cert, key)
}

type engineParams struct {
endpoint string
ca string
cert string
key string
}

func (ep engineParams) getCacheKey() string {
return getEngineCacheKey(ep.endpoint, ep.ca, ep.cert, ep.key)
}

func validateEngine(ctx context.Context, engine engine.API, timeout time.Duration) (err error) {
utils.WithTimeout(ctx, timeout, func(ctx context.Context) {
err = engine.Ping(ctx)
})
return err
}

func getEnginePrefix(endpoint string) (string, error) {
for prefix := range engines {
if strings.HasPrefix(endpoint, prefix) {
return prefix, nil
}
}
return "", types.NewDetailedErr(types.ErrNodeFormat, fmt.Sprintf("endpoint invalid %v", endpoint))
}

func getEngineCacheKey(endpoint, ca, cert, key string) string {
return fmt.Sprintf("%v-%v", endpoint, utils.SHA256(fmt.Sprintf(":%v:%v:%v", ca, cert, key))[:8])
}

// newEngine get engine
func newEngine(ctx context.Context, config types.Config, nodename, endpoint, ca, cert, key string) (client engine.API, err error) {
prefix, err := getEnginePrefix(endpoint)
Expand All @@ -212,12 +221,3 @@ func newEngine(ctx context.Context, config types.Config, nodename, endpoint, ca,
}
return client, nil
}

func getEnginePrefix(endpoint string) (string, error) {
for prefix := range engines {
if strings.HasPrefix(endpoint, prefix) {
return prefix, nil
}
}
return "", types.NewDetailedErr(types.ErrNodeFormat, fmt.Sprintf("endpoint invalid %v", endpoint))
}
2 changes: 1 addition & 1 deletion engine/mocks/fakeengine/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ func MakeClient(ctx context.Context, config coretypes.Config, nodename, endpoint
e.On("VirtualizationUpdateResource", mock.Anything, mock.Anything, mock.Anything).Return(nil)

e.On("VirtualizationCopyFrom", mock.Anything, mock.Anything, mock.Anything).Return([]byte("d1...\nd2...\n"), 0, 0, int64(0), nil)
e.On("ResourceValidate", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
// e.On("ResourceValidate", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
return e, nil
}
2 changes: 1 addition & 1 deletion engine/types/virtualization.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type VirtualizationResource struct {
Volumes []string `json:"volumes" mapstructure:"volumes"`
VolumePlan map[string]map[string]int64 `json:"volume_plan" mapstructure:"volume_plan"` // literal VolumePlan
VolumeChanged bool `json:"volume_changed" mapstructure:"volume_changed"` // indicate whether new volumes contained in realloc request
IOPSOptions map[string]string `json:"iops_options" mapstructure:"iops_options"` // format: {device_name: "read-iops:write-iops:read-bps:write-bps"}
IOPSOptions map[string]string `json:"iops_options" mapstructure:"IOPS_options"` // format: {device_name: "read-IOPS:write-IOPS:read-bps:write-bps"}
Remap bool `json:"remap" mapstructure:"remap"`
}

Expand Down
39 changes: 24 additions & 15 deletions resources/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,13 @@ func (bp *BinaryPlugin) GetNodesDeployCapacity(ctx context.Context, nodes []stri
}

// GetNodeResourceInfo .
func (bp *BinaryPlugin) GetNodeResourceInfo(ctx context.Context, nodename string, workloads []*coretypes.Workload, fix bool) (resp *GetNodeResourceInfoResponse, err error) {
workloadMap := map[string]coretypes.WorkloadResourceArgs{}
for _, workload := range workloads {
workloadMap[workload.ID] = workload.ResourceArgs[bp.Name()]
}
func (bp *BinaryPlugin) GetNodeResourceInfo(ctx context.Context, nodename string, workloads []*coretypes.Workload) (resp *GetNodeResourceInfoResponse, err error) {
return bp.getNodeResourceInfo(ctx, nodename, workloads, false)
}

req := GetNodeResourceInfoRequest{
NodeName: nodename,
WorkloadMap: workloadMap,
Fix: fix,
}
resp = &GetNodeResourceInfoResponse{}
if err = bp.call(ctx, getNodeResourceInfoCommand, req, resp); err != nil {
return nil, err
}
return resp, nil
// FixNodeResource .
func (bp *BinaryPlugin) FixNodeResource(ctx context.Context, nodename string, workloads []*coretypes.Workload) (resp *GetNodeResourceInfoResponse, err error) {
return bp.getNodeResourceInfo(ctx, nodename, workloads, true)
}

// SetNodeResourceInfo .
Expand Down Expand Up @@ -282,3 +273,21 @@ func (bp *BinaryPlugin) call(ctx context.Context, cmd string, req interface{}, r
}
return nil
}

func (bp *BinaryPlugin) getNodeResourceInfo(ctx context.Context, nodename string, workloads []*coretypes.Workload, fix bool) (resp *GetNodeResourceInfoResponse, err error) {
workloadMap := map[string]coretypes.WorkloadResourceArgs{}
for _, workload := range workloads {
workloadMap[workload.ID] = workload.ResourceArgs[bp.Name()]
}

req := GetNodeResourceInfoRequest{
NodeName: nodename,
WorkloadMap: workloadMap,
Fix: fix,
}
resp = &GetNodeResourceInfoResponse{}
if err = bp.call(ctx, getNodeResourceInfoCommand, req, resp); err != nil {
return nil, err
}
return resp, nil
}
Loading