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
32 changes: 32 additions & 0 deletions cluster/calcium/raw_engine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package calcium

import (
"context"
"sync"

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

func (c *Calcium) RawEngine(ctx context.Context, opts *types.RawEngineOptions) (msg *types.RawEngineMessage, err error) {
ID := opts.ID
logger := log.WithFunc("calcium.RawEngine").WithField("ID", opts.ID)
var wg sync.WaitGroup
wg.Add(1)
_ = c.pool.Invoke(func() {
defer wg.Done()
err = c.withWorkloadLocked(ctx, ID, func(ctx context.Context, workload *types.Workload) error {
msg, err = workload.RawEngine(ctx, opts)
return err
})

if err == nil {
logger.Infof(ctx, "Workload %s", ID)
logger.Infof(ctx, "%+v", msg)
}
})
wg.Wait()

logger.Error(ctx, err)
return
}
34 changes: 34 additions & 0 deletions cluster/calcium/raw_engine_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package calcium

import (
"context"
"testing"

enginemocks "github.com/projecteru2/core/engine/mocks"
enginetypes "github.com/projecteru2/core/engine/types"
lockmocks "github.com/projecteru2/core/lock/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestRawEngine(t *testing.T) {
c := NewTestCluster()
ctx := context.Background()
store := c.store.(*storemocks.Store)
lock := &lockmocks.DistributedLock{}
lock.On("Lock", mock.Anything).Return(ctx, nil)
lock.On("Unlock", mock.Anything).Return(nil)
store.On("CreateLock", mock.Anything, mock.Anything).Return(lock, nil)
workload := &types.Workload{
ID: "id1",
Privileged: true,
}
engine := &enginemocks.API{}
workload.Engine = engine
store.On("GetWorkloads", mock.Anything, mock.Anything).Return([]*types.Workload{workload}, nil)
engine.On("RawEngine", mock.Anything, mock.Anything).Return(&enginetypes.RawEngineResult{}, nil).Once()
_, err := c.RawEngine(ctx, &types.RawEngineOptions{ID: "id1", Op: "xxxx"})
assert.NoError(t, err)
}
1 change: 1 addition & 0 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type Cluster interface {
ReallocResource(ctx context.Context, opts *types.ReallocOptions) error
LogStream(ctx context.Context, opts *types.LogStreamOptions) (chan *types.LogStreamMessage, error)
RunAndWait(ctx context.Context, opts *types.DeployOptions, inCh <-chan []byte) ([]string, <-chan *types.AttachWorkloadMessage, error)
RawEngine(ctx context.Context, opts *types.RawEngineOptions) (*types.RawEngineMessage, error)
// finalizer
Finalizer()

Expand Down
28 changes: 27 additions & 1 deletion cluster/mocks/Cluster.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions engine/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ func (e *Engine) VirtualizationResume(context.Context, string) error {
return nil
}

func (e *Engine) RawEngine(context.Context, *enginetypes.RawEngineOptions) (res *enginetypes.RawEngineResult, err error) {
return nil, nil
}

// VirtualizationRemove remove virtualization
func (e *Engine) VirtualizationRemove(ctx context.Context, ID string, removeVolumes, force bool) error {
if err := e.client.ContainerRemove(ctx, ID, dockertypes.ContainerRemoveOptions{RemoveVolumes: removeVolumes, Force: force}); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ type API interface {
VirtualizationWait(ctx context.Context, ID, state string) (*enginetypes.VirtualizationWaitResult, error)
VirtualizationUpdateResource(ctx context.Context, ID string, params resourcetypes.Resources) error
VirtualizationCopyFrom(ctx context.Context, ID, path string) (content []byte, uid, gid int, mode int64, _ error)

RawEngine(ctx context.Context, opts *enginetypes.RawEngineOptions) (*enginetypes.RawEngineResult, error)
}
1 change: 0 additions & 1 deletion engine/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var (
engines = map[string]factory{
docker.TCPPrefixKey: docker.MakeClient,
docker.SockPrefixKey: docker.MakeClient,
virt.HTTPPrefixKey: virt.MakeClient,
virt.GRPCPrefixKey: virt.MakeClient,
systemd.TCPPrefix: systemd.MakeClient,
fakeengine.PrefixKey: fakeengine.MakeClient,
Expand Down
4 changes: 4 additions & 0 deletions engine/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ func (f *EngineWithErr) VirtualizationRemove(context.Context, string, bool, bool
return f.DefaultErr
}

func (f *EngineWithErr) RawEngine(context.Context, *enginetypes.RawEngineOptions) (*enginetypes.RawEngineResult, error) {
return nil, f.DefaultErr
}

// VirtualizationInspect .
func (f *EngineWithErr) VirtualizationInspect(context.Context, string) (*enginetypes.VirtualizationInfo, error) {
return nil, f.DefaultErr
Expand Down
28 changes: 27 additions & 1 deletion engine/mocks/API.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions engine/types/raw_engine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package types

type RawEngineOptions struct {
ID string
Op string
Params []byte
}

type RawEngineResult struct {
ID string
Data []byte
}
21 changes: 17 additions & 4 deletions engine/virt/virt.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
)

const (
// HTTPPrefixKey indicate http yavirtd
HTTPPrefixKey = "virt://"
// GRPCPrefixKey indicates grpc yavirtd
GRPCPrefixKey = "virt-grpc://"
// ImageUserKey indicates the image's owner
Expand All @@ -47,8 +45,6 @@ type Virt struct {
func MakeClient(_ context.Context, config coretypes.Config, nodename, endpoint, ca, _, _ string) (engine.API, error) {
var uri string
switch {
case strings.HasPrefix(endpoint, HTTPPrefixKey):
uri = fmt.Sprintf("http://%s/%s", strings.TrimPrefix(endpoint, HTTPPrefixKey), config.Virt.APIVersion)
case strings.HasPrefix(endpoint, GRPCPrefixKey):
uri = "grpc://" + strings.TrimPrefix(endpoint, GRPCPrefixKey)
default:
Expand Down Expand Up @@ -289,6 +285,23 @@ func (v *Virt) VirtualizationResume(ctx context.Context, ID string) (err error)
return
}

func (v *Virt) RawEngine(ctx context.Context, opts *enginetypes.RawEngineOptions) (res *enginetypes.RawEngineResult, err error) {
req := virttypes.RawEngineReq{
ID: opts.ID,
Op: opts.Op,
Params: opts.Params,
}
resp, err := v.client.RawEngine(ctx, req)
if err != nil {
return
}
res = &enginetypes.RawEngineResult{
ID: resp.ID,
Data: resp.Data,
}
return
}

// VirtualizationInspect gets a guest.
func (v *Virt) VirtualizationInspect(ctx context.Context, ID string) (*enginetypes.VirtualizationInfo, error) {
guest, err := v.client.GetGuest(ctx, ID)
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/panjf2000/ants/v2 v2.7.3
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/projecteru2/libyavirt v0.0.0-20230725071905-9785e974d625
github.com/projecteru2/libyavirt v0.0.0-20230921032447-a617cf0c746c
github.com/prometheus/client_golang v1.15.0
github.com/rs/zerolog v1.29.1
github.com/sanity-io/litter v1.5.5
Expand Down Expand Up @@ -88,7 +88,6 @@ require (
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jonboulle/clockwork v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/juju/errors v1.0.0 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/kr/pretty v0.3.1 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,6 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/juju/errors v1.0.0 h1:yiq7kjCLll1BiaRuNY53MGI0+EQ3rF6GB+wvboZDefM=
github.com/juju/errors v1.0.0/go.mod h1:B5x9thDqx0wIMH3+aLIMP9HjItInYWObRovoCFM5Qe8=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
github.com/kataras/golog v0.0.10/go.mod h1:yJ8YKCmyL+nWjERB90Qwn+bdyBZsaQwU3bTVFgkFIp8=
Expand Down Expand Up @@ -459,8 +457,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/projecteru2/libyavirt v0.0.0-20230725071905-9785e974d625 h1:liDnxQ0JxvOLC0/tUVRlz4tG9r/xbcp1NXgNVNBJsLQ=
github.com/projecteru2/libyavirt v0.0.0-20230725071905-9785e974d625/go.mod h1:N41KaKmqbailweGs4x/mt2H0O0Y7MizObZQ+igLdzpw=
github.com/projecteru2/libyavirt v0.0.0-20230921032447-a617cf0c746c h1:zwbTS+K8aKgXHU/7YVU4okk7fqrAE3W+yJjMRE3qdQA=
github.com/projecteru2/libyavirt v0.0.0-20230921032447-a617cf0c746c/go.mod h1:+EcdWF8KyTf2u8Zxu3397nSmalCSmpuxvGwcX1g3RL0=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g=
Expand Down
2 changes: 2 additions & 0 deletions rpc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const (
GetWorkloadsStatus codes.Code = 1055
// SetWorkloadsStatus .
SetWorkloadsStatus codes.Code = 1056
// RawEngine
RawEngineStatus codes.Code = 1057

// Copy .
Copy codes.Code = 1061
Expand Down
Loading