Skip to content

Commit 1f2842b

Browse files
authored
Add transaction interface in create node (#305)
1 parent b92cc78 commit 1f2842b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+862
-489
lines changed

api/application.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func (api *API) UpdateNodeAndAppIndex(namespace string, app *specV1.Application)
348348
if err != nil {
349349
return err
350350
}
351-
return api.Index.RefreshNodesIndexByApp(namespace, app.Name, nodes)
351+
return api.Index.RefreshNodesIndexByApp(nil, namespace, app.Name, nodes)
352352
}
353353

354354
func (api *API) DeleteNodeAndAppIndex(namespace string, app *specV1.Application) error {
@@ -357,7 +357,7 @@ func (api *API) DeleteNodeAndAppIndex(namespace string, app *specV1.Application)
357357
return err
358358
}
359359

360-
return api.Index.RefreshNodesIndexByApp(namespace, app.Name, make([]string, 0))
360+
return api.Index.RefreshNodesIndexByApp(nil, namespace, app.Name, make([]string, 0))
361361
}
362362

363363
func (api *API) ToApplicationView(app *specV1.Application) (*models.ApplicationView, error) {

api/application_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ func TestCreateContainerApplication(t *testing.T) {
608608
sApp.EXPECT().Get(appView.Namespace, "eden2", "").Return(eden2, nil).Return(eden2, nil).Times(1)
609609
sApp.EXPECT().CreateWithBase(appView.Namespace, gomock.Any(), eden2).Return(eden2, nil)
610610
sNode.EXPECT().UpdateNodeAppVersion(appView.Namespace, gomock.Any()).Return([]string{}, nil).Times(1)
611-
sIndex.EXPECT().RefreshNodesIndexByApp(appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
611+
sIndex.EXPECT().RefreshNodesIndexByApp(nil, appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
612612
sSecret.EXPECT().Get(appView.Namespace, "secret01", "").Return(secret, nil).Times(1)
613613
w = httptest.NewRecorder()
614614
body, _ = json.Marshal(appView)
@@ -801,7 +801,7 @@ func TestCreateApplicationHasCertificates(t *testing.T) {
801801
sApp.EXPECT().Get(appView.Namespace, "abc", "").Return(nil, common.Error(common.ErrResourceNotFound)).Times(1)
802802
sApp.EXPECT().CreateWithBase(appView.Namespace, app, nil).Return(app, nil)
803803
sNode.EXPECT().UpdateNodeAppVersion(appView.Namespace, gomock.Any()).Return([]string{}, nil).Times(1)
804-
sIndex.EXPECT().RefreshNodesIndexByApp(appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
804+
sIndex.EXPECT().RefreshNodesIndexByApp(nil, appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
805805
sSecret.EXPECT().Get(appView.Namespace, "secret01", "").Return(secret, nil).Times(1)
806806
sSecret.EXPECT().Get(appView.Namespace, "registry01", "").Return(secretRegistry, nil).Times(1)
807807
sSecret.EXPECT().Get(appView.Namespace, "certificate01", "").Return(secretCertificate, nil).Times(1)
@@ -862,7 +862,7 @@ func TestUpdateContainerApplication(t *testing.T) {
862862

863863
sApp.EXPECT().Get(gomock.Any(), "abc", gomock.Any()).Return(mApp, nil).AnyTimes()
864864
sApp.EXPECT().Update(mApp.Namespace, gomock.Any()).Return(mApp2, nil)
865-
sIndex.EXPECT().RefreshNodesIndexByApp(mApp.Namespace, mApp.Name, gomock.Any()).Return(nil).Times(2)
865+
sIndex.EXPECT().RefreshNodesIndexByApp(nil, mApp.Namespace, mApp.Name, gomock.Any()).Return(nil).Times(2)
866866
sNode.EXPECT().DeleteNodeAppVersion(gomock.Any(), gomock.Any()).Return(nil, nil)
867867
sNode.EXPECT().UpdateNodeAppVersion(gomock.Any(), gomock.Any()).Return([]string{}, nil)
868868
w = httptest.NewRecorder()
@@ -1043,7 +1043,7 @@ func TestUpdateNativeNotFunctionApplication(t *testing.T) {
10431043
sApp.EXPECT().Get(appView.Namespace, "abc", "").Return(nil, common.Error(common.ErrResourceNotFound)).Times(1)
10441044
sApp.EXPECT().CreateWithBase(appView.Namespace, gomock.Any(), nil).Return(app1, nil)
10451045
sNode.EXPECT().UpdateNodeAppVersion(appView.Namespace, gomock.Any()).Return([]string{}, nil).Times(1)
1046-
sIndex.EXPECT().RefreshNodesIndexByApp(appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
1046+
sIndex.EXPECT().RefreshNodesIndexByApp(nil, appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
10471047
w := httptest.NewRecorder()
10481048
body, _ := json.Marshal(appView)
10491049
req, _ := http.NewRequest(http.MethodPost, "/v1/apps", bytes.NewReader(body))
@@ -1187,7 +1187,7 @@ func TestUpdateNativeNotFunctionApplication(t *testing.T) {
11871187
sApp.EXPECT().Get(appView.Namespace, "abc", "").Return(nil, common.Error(common.ErrResourceNotFound)).Times(1)
11881188
sApp.EXPECT().CreateWithBase(appView.Namespace, gomock.Any(), nil).Return(app12, nil)
11891189
sNode.EXPECT().UpdateNodeAppVersion(appView.Namespace, gomock.Any()).Return([]string{}, nil).Times(1)
1190-
sIndex.EXPECT().RefreshNodesIndexByApp(appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
1190+
sIndex.EXPECT().RefreshNodesIndexByApp(nil, appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
11911191
w = httptest.NewRecorder()
11921192
body, _ = json.Marshal(appView12)
11931193
req, _ = http.NewRequest(http.MethodPost, "/v1/apps", bytes.NewReader(body))
@@ -1310,7 +1310,7 @@ func TestUpdateNativeNotFunctionApplication(t *testing.T) {
13101310
sApp.EXPECT().Get(appView.Namespace, "abc", "").Return(app1, nil).Times(1)
13111311
sApp.EXPECT().Update(appView.Namespace, gomock.Any()).Return(app2, nil)
13121312
sNode.EXPECT().UpdateNodeAppVersion(appView.Namespace, gomock.Any()).Return([]string{}, nil).Times(1)
1313-
sIndex.EXPECT().RefreshNodesIndexByApp(appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
1313+
sIndex.EXPECT().RefreshNodesIndexByApp(nil, appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
13141314

13151315
w = httptest.NewRecorder()
13161316
body, _ = json.Marshal(appView2)
@@ -1747,7 +1747,7 @@ func TestCreateFunctionApplication(t *testing.T) {
17471747
sConfig.EXPECT().Upsert(appView.Namespace, gomock.Any()).Return(config, nil).Times(2)
17481748
sApp.EXPECT().CreateWithBase(appView.Namespace, gomock.Any(), gomock.Any()).Return(mApp, nil).Times(1)
17491749
sNode.EXPECT().UpdateNodeAppVersion(appView.Namespace, gomock.Any()).Return([]string{}, nil).Times(1)
1750-
sIndex.EXPECT().RefreshNodesIndexByApp(appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
1750+
sIndex.EXPECT().RefreshNodesIndexByApp(nil, appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
17511751
sConfig.EXPECT().Get(appView.Namespace, gomock.Any(), "").Return(config, nil).AnyTimes()
17521752

17531753
w = httptest.NewRecorder()
@@ -2246,7 +2246,7 @@ func TestUpdateFunctionApplication(t *testing.T) {
22462246
sConfig.EXPECT().Upsert(namespace, gomock.Any()).Return(config4, nil).Times(1)
22472247
sApp.EXPECT().Update(namespace, gomock.Any()).Return(newApp, nil).Times(1)
22482248
sNode.EXPECT().UpdateNodeAppVersion(namespace, gomock.Any()).Return([]string{}, nil).Times(1)
2249-
sIndex.EXPECT().RefreshNodesIndexByApp(namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
2249+
sIndex.EXPECT().RefreshNodesIndexByApp(nil, namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
22502250
sConfig.EXPECT().Delete(namespace, gomock.Any()).Return(nil).Times(3)
22512251
sConfig.EXPECT().Get(namespace, "baetyl-function-config-app-service-2", "").Return(config2, nil).Times(1)
22522252
sConfig.EXPECT().Get(namespace, "baetyl-function-config-app-service-3", "").Return(config2, nil).Times(1)
@@ -2303,7 +2303,7 @@ func TestDeleteApplication(t *testing.T) {
23032303
// 200
23042304
sApp.EXPECT().Get(gomock.Any(), "abc", gomock.Any()).Return(app, nil).Times(1)
23052305
sApp.EXPECT().Delete(app.Namespace, app.Name, "").Return(nil).Times(1)
2306-
sIndex.EXPECT().RefreshNodesIndexByApp(app.Namespace, app.Name, gomock.Any()).Return(nil).Times(1)
2306+
sIndex.EXPECT().RefreshNodesIndexByApp(nil, app.Namespace, app.Name, gomock.Any()).Return(nil).Times(1)
23072307
sNode.EXPECT().DeleteNodeAppVersion(gomock.Any(), gomock.Any()).Return(nil, nil).Times(1)
23082308
req, _ = http.NewRequest(http.MethodDelete, "/v1/apps/abc", nil)
23092309
w = httptest.NewRecorder()
@@ -2391,7 +2391,7 @@ func TestDeleteApplication(t *testing.T) {
23912391

23922392
// 200
23932393
sApp.EXPECT().Get(gomock.Any(), "abc", gomock.Any()).Return(app, nil).Times(1)
2394-
sIndex.EXPECT().RefreshNodesIndexByApp(app.Namespace, app.Name, gomock.Any()).Return(nil)
2394+
sIndex.EXPECT().RefreshNodesIndexByApp(nil, app.Namespace, app.Name, gomock.Any()).Return(nil)
23952395
sNode.EXPECT().DeleteNodeAppVersion(gomock.Any(), gomock.Any()).Return(nil, nil)
23962396
sApp.EXPECT().Delete(app.Namespace, app.Name, "").Return(nil)
23972397
sConfig.EXPECT().Delete(app.Namespace, "baetyl-function-config-app-service-xxxxxxxxx").Return(nil).Times(1)
@@ -2716,7 +2716,7 @@ func TestCreateKubeFunctionApplication(t *testing.T) {
27162716
sConfig.EXPECT().Upsert(appView.Namespace, gomock.Any()).Return(config, nil).Times(2)
27172717
sApp.EXPECT().CreateWithBase(appView.Namespace, gomock.Any(), gomock.Any()).Return(mApp, nil).Times(1)
27182718
sNode.EXPECT().UpdateNodeAppVersion(appView.Namespace, gomock.Any()).Return([]string{}, nil).Times(1)
2719-
sIndex.EXPECT().RefreshNodesIndexByApp(appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
2719+
sIndex.EXPECT().RefreshNodesIndexByApp(nil, appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
27202720
sConfig.EXPECT().Get(appView.Namespace, gomock.Any(), "").Return(config, nil).AnyTimes()
27212721

27222722
w = httptest.NewRecorder()
@@ -2833,7 +2833,7 @@ func TestCreateKubeNotFunctionApplication(t *testing.T) {
28332833
sApp.EXPECT().Get(appView.Namespace, "eden2", "").Return(eden2, nil).Return(eden2, nil).Times(1)
28342834
sApp.EXPECT().CreateWithBase(appView.Namespace, gomock.Any(), eden2).Return(eden2, nil)
28352835
sNode.EXPECT().UpdateNodeAppVersion(appView.Namespace, gomock.Any()).Return([]string{}, nil).Times(1)
2836-
sIndex.EXPECT().RefreshNodesIndexByApp(appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
2836+
sIndex.EXPECT().RefreshNodesIndexByApp(nil, appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
28372837
sSecret.EXPECT().Get(appView.Namespace, "secret01", "").Return(secret, nil).Times(1)
28382838
w := httptest.NewRecorder()
28392839
body, _ := json.Marshal(appView)
@@ -3152,7 +3152,7 @@ func TestCreateNativeFunctionApplication(t *testing.T) {
31523152
sConfig.EXPECT().Upsert(appView.Namespace, gomock.Any()).Return(config, nil).Times(2)
31533153
sApp.EXPECT().CreateWithBase(appView.Namespace, gomock.Any(), gomock.Any()).Return(mApp, nil).Times(1)
31543154
sNode.EXPECT().UpdateNodeAppVersion(appView.Namespace, gomock.Any()).Return([]string{}, nil).Times(1)
3155-
sIndex.EXPECT().RefreshNodesIndexByApp(appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
3155+
sIndex.EXPECT().RefreshNodesIndexByApp(nil, appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
31563156
sConfig.EXPECT().Get(appView.Namespace, gomock.Any(), "").Return(config, nil).AnyTimes()
31573157

31583158
w = httptest.NewRecorder()
@@ -3283,7 +3283,7 @@ func TestCreateNativeNotFunctionApplication(t *testing.T) {
32833283
sApp.EXPECT().Get(appView.Namespace, "eden2", "").Return(eden2, nil).Return(eden2, nil).Times(1)
32843284
sApp.EXPECT().CreateWithBase(appView.Namespace, gomock.Any(), eden2).Return(eden2, nil)
32853285
sNode.EXPECT().UpdateNodeAppVersion(appView.Namespace, gomock.Any()).Return([]string{}, nil).Times(1)
3286-
sIndex.EXPECT().RefreshNodesIndexByApp(appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
3286+
sIndex.EXPECT().RefreshNodesIndexByApp(nil, appView.Namespace, gomock.Any(), gomock.Any()).Return(nil).Times(1)
32873287
sSecret.EXPECT().Get(appView.Namespace, "secret01", "").Return(secret, nil).Times(1)
32883288
w := httptest.NewRecorder()
32893289
body, _ := json.Marshal(appView)

api/certificate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (api *API) CreateCertificate(c *common.Context) (interface{}, error) {
6161
if err = cfg.ParseCertInfo(); err != nil {
6262
return nil, err
6363
}
64-
res, err := api.Secret.Create(ns, cfg.ToSecret())
64+
res, err := api.Secret.Create(nil, ns, cfg.ToSecret())
6565
if err != nil {
6666
return nil, err
6767
}

api/certificate_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ tu5nww5RdjCz4Uks08P2GNmZjLO81MgYkhR7B9wi3KDNxg==
129129
Version: "1234",
130130
}
131131
mkSecretService.EXPECT().Get(gomock.Any(), cert1.Name, gomock.Any()).Return(nil, nil).Times(1)
132-
mkSecretService.EXPECT().Create(gomock.Any(), temp1).Return(res1, nil).Times(1)
132+
mkSecretService.EXPECT().Create(gomock.Any(), gomock.Any(), temp1).Return(res1, nil).Times(1)
133133
w := httptest.NewRecorder()
134134
body, _ := json.Marshal(cert1)
135135
req, _ := http.NewRequest(http.MethodPost, "/v1/certificates", bytes.NewReader(body))
@@ -196,7 +196,7 @@ RcKyjhh1
196196
Version: "1234",
197197
}
198198
mkSecretService.EXPECT().Get(gomock.Any(), cert2.Name, gomock.Any()).Return(nil, nil).Times(1)
199-
mkSecretService.EXPECT().Create(gomock.Any(), temp2).Return(res2, nil).Times(1)
199+
mkSecretService.EXPECT().Create(gomock.Any(), gomock.Any(), temp2).Return(res2, nil).Times(1)
200200
w = httptest.NewRecorder()
201201
body, _ = json.Marshal(cert2)
202202
req, _ = http.NewRequest(http.MethodPost, "/v1/certificates", bytes.NewReader(body))
@@ -357,7 +357,7 @@ RcKyjhh1
357357
temp8 := cert8.ToSecret()
358358

359359
mkSecretService.EXPECT().Get(gomock.Any(), cert8.Name, gomock.Any()).Return(nil, nil).Times(1)
360-
mkSecretService.EXPECT().Create(gomock.Any(), temp8).Return(nil, fmt.Errorf("error")).Times(1)
360+
mkSecretService.EXPECT().Create(gomock.Any(), gomock.Any(), temp8).Return(nil, fmt.Errorf("error")).Times(1)
361361
w = httptest.NewRecorder()
362362
body, _ = json.Marshal(cert8)
363363
req, _ = http.NewRequest(http.MethodPost, "/v1/certificates", bytes.NewReader(body))

api/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (api *API) CreateConfig(c *common.Context) (interface{}, error) {
7676
common.Field("error", "this name is already in use"))
7777
}
7878

79-
config, err = api.Config.Create(ns, config)
79+
config, err = api.Config.Create(nil, ns, config)
8080
if err != nil {
8181
return nil, err
8282
}

api/config_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func TestCreateConfig(t *testing.T) {
291291
System: false,
292292
}
293293
sConfig.EXPECT().Get(mConf.Namespace, mConf.Name, gomock.Any()).Return(nil, nil).Times(1)
294-
sConfig.EXPECT().Create(mConf.Namespace, gomock.Any()).Return(res, nil).Times(1)
294+
sConfig.EXPECT().Create(nil, mConf.Namespace, gomock.Any()).Return(res, nil).Times(1)
295295

296296
w = httptest.NewRecorder()
297297
body, _ = json.Marshal(mConf)
@@ -377,7 +377,7 @@ func TestCreateConfig(t *testing.T) {
377377
System: false,
378378
}
379379
sConfig.EXPECT().Get(mConf.Namespace, mConf.Name, gomock.Any()).Return(nil, nil).Times(1)
380-
sConfig.EXPECT().Create(mConf.Namespace, gomock.Any()).Return(res, nil).Times(1)
380+
sConfig.EXPECT().Create(nil, mConf.Namespace, gomock.Any()).Return(res, nil).Times(1)
381381

382382
w = httptest.NewRecorder()
383383
body, _ = json.Marshal(mConf)
@@ -429,7 +429,7 @@ func TestCreateConfig(t *testing.T) {
429429
System: false,
430430
}
431431
sConfig.EXPECT().Get(mConf.Namespace, mConf.Name, gomock.Any()).Return(nil, nil).Times(1)
432-
sConfig.EXPECT().Create(mConf.Namespace, gomock.Any()).Return(res, nil).Times(1)
432+
sConfig.EXPECT().Create(nil, mConf.Namespace, gomock.Any()).Return(res, nil).Times(1)
433433

434434
w = httptest.NewRecorder()
435435
body, _ = json.Marshal(mConf)
@@ -466,7 +466,7 @@ func TestCreateConfig(t *testing.T) {
466466
}
467467

468468
sConfig.EXPECT().Get(mConf.Namespace, mConf.Name, gomock.Any()).Return(nil, nil).Times(1)
469-
sConfig.EXPECT().Create(mConf.Namespace, gomock.Any()).Return(nil, errors.New("err")).Times(1)
469+
sConfig.EXPECT().Create(nil, mConf.Namespace, gomock.Any()).Return(nil, errors.New("err")).Times(1)
470470

471471
w = httptest.NewRecorder()
472472
body, _ = json.Marshal(mConf)

api/node.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (api *API) CreateNode(c *common.Context) (interface{}, error) {
170170
if n.Accelerator == v1.NVAccelerator {
171171
n.SysApps = append(n.SysApps, v1.BaetylGPUMetrics)
172172
}
173-
node, err := api.Node.Create(n.Namespace, n)
173+
node, err := api.Node.Create(nil, n.Namespace, n)
174174
if err != nil {
175175
if e := api.ReleaseQuota(ns, plugin.QuotaNode, NodeNumber); e != nil {
176176
log.L().Error("ReleaseQuota error", log.Error(e))
@@ -275,7 +275,7 @@ func (api *API) deleteAllSysAppsOfNode(node *v1.Node) (interface{}, error) {
275275
api.deleteSysApps(node.Namespace, sysAppNames)
276276

277277
for _, v := range sysAppNames {
278-
if err := api.Index.RefreshNodesIndexByApp(node.Namespace, v, make([]string, 0)); err != nil {
278+
if err := api.Index.RefreshNodesIndexByApp(nil, node.Namespace, v, make([]string, 0)); err != nil {
279279
common.LogDirtyData(err,
280280
log.Any("type", common.Index),
281281
log.Any(common.KeyContextNamespace, node.Namespace),
@@ -671,7 +671,7 @@ func (api *API) updateAddedSysApps(ns, node string, freshAppAlias []string) erro
671671
return nil
672672
}
673673

674-
freshApps, err := api.SysApp.GenOptionalApps(ns, node, freshAppAlias)
674+
freshApps, err := api.SysApp.GenOptionalApps(nil, ns, node, freshAppAlias)
675675
if err != nil {
676676
return err
677677
}
@@ -712,7 +712,7 @@ func (api *API) deleteDeletedSysApps(node *v1.Node, obsoleteAppAlias []string) e
712712
}
713713

714714
for _, v := range obsoleteAppNames {
715-
if err := api.Index.RefreshNodesIndexByApp(node.Namespace, v, make([]string, 0)); err != nil {
715+
if err := api.Index.RefreshNodesIndexByApp(nil, node.Namespace, v, make([]string, 0)); err != nil {
716716
common.LogDirtyData(err,
717717
log.Any("type", common.Index),
718718
log.Any(common.KeyContextNamespace, node.Namespace),

0 commit comments

Comments
 (0)