Skip to content

Commit a984138

Browse files
committed
pcm ali sdk CRUD
Signed-off-by: zhouqj <[email protected]>
1 parent 29d036c commit a984138

File tree

9 files changed

+261
-208
lines changed

9 files changed

+261
-208
lines changed

adaptor/pod_adaptor/server/pod/ali/create_container_group.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func CreateContainerGroup(request *CreateContainerGroupRequest) (response *Creat
2323
memoryPod := container[0].Memory
2424

2525
requestPCM := &pbpod.CreatePodReq{
26+
RequestSource: "ali",
2627
Provider: provider,
2728
AccountName: tenanters[0].AccountName(),
2829
PodName: request.ContainerGroupName,

adaptor/pod_adaptor/server/pod/ali/delete_container_group.go

+7-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adaptor/pod_adaptor/server/pod/ali/describe_container_groups.go

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
//Licensed under the Apache License, Version 2.0 (the "License");
2-
//you may not use this file except in compliance with the License.
3-
//You may obtain a copy of the License at
4-
//
5-
//http://www.apache.org/licenses/LICENSE-2.0
6-
//
7-
//Unless required by applicable law or agreed to in writing, software
8-
//distributed under the License is distributed on an "AS IS" BASIS,
9-
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10-
//See the License for the specific language governing permissions and
11-
//limitations under the License.
12-
//
13-
// Code generated by Alibaba Cloud SDK Code Generator.
14-
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
15-
161
package ali
172

183
import (
@@ -29,6 +14,7 @@ func DescribeContainerGroups(request *DescribeContainerGroupsRequest) (response
2914

3015
provider := pbtenant.CloudProvider(request.ProviderId)
3116
containerGroups := make([]DescribeContainerGroupsContainerGroup0, 0)
17+
//trans Ali request to PCM request
3218
requestPCM := &pbpod.ListPodReq{
3319
RequestSource: "ali",
3420
Provider: provider,

adaptor/pod_adaptor/server/pod/ali/update_container_group.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adaptor/pod_adaptor/server/pod/pod.go

+17-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package pod
22

33
import (
44
"context"
5-
"flag"
65
"fmt"
76
"sync"
87

@@ -99,7 +98,10 @@ func CreatePod(ctx context.Context, req *pbpod.CreatePodReq) (*pbpod.CreatePodRe
9998
var (
10099
pod poder.Poder
101100
)
102-
101+
//pcm adk过来的请求需要从用户本地读取配置文件
102+
if len(req.RequestSource) > 0 {
103+
tenanter.GenTenanter("configs/config.yaml")
104+
}
103105
tenanters, err := tenanter.GetTenanters(req.Provider)
104106
if err != nil {
105107
return nil, errors.WithMessage(err, "getTenanters error")
@@ -126,7 +128,10 @@ func DeletePod(ctx context.Context, req *pbpod.DeletePodReq) (*pbpod.DeletePodRe
126128
var (
127129
pod poder.Poder
128130
)
129-
131+
//pcm adk过来的请求需要从用户本地读取配置文件
132+
if len(req.RequestSource) > 0 {
133+
tenanter.GenTenanter("configs/config.yaml")
134+
}
130135
tenanters, err := tenanter.GetTenanters(req.Provider)
131136
if err != nil {
132137
return nil, errors.WithMessage(err, "getTenanters error")
@@ -153,7 +158,10 @@ func UpdatePod(ctx context.Context, req *pbpod.UpdatePodReq) (*pbpod.UpdatePodRe
153158
var (
154159
pod poder.Poder
155160
)
156-
161+
//pcm adk过来的请求需要从用户本地读取配置文件
162+
if len(req.RequestSource) > 0 {
163+
tenanter.GenTenanter("configs/config.yaml")
164+
}
157165
tenanters, err := tenanter.GetTenanters(req.Provider)
158166
if err != nil {
159167
return nil, errors.WithMessage(err, "getTenanters error")
@@ -210,27 +218,13 @@ func ListPod(ctx context.Context, req *pbpod.ListPodReq) (*pbpod.ListPodResp, er
210218
pods []*pbpod.PodInstance
211219
tenanters []tenanter.Tenanter
212220
)
213-
//ali adk过来的请求需要从用户本地读取配置文件
214-
if req.RequestSource == "ali" {
215-
216-
var configFile string
217-
flag.StringVar(&configFile, "conf", "configs/config.yaml", "config.yaml")
218-
flag.Parse()
219-
defer glog.Flush()
220-
221-
if err := tenanter.LoadCloudConfigsFromFile(configFile); err != nil {
222-
if !errors.Is(err, tenanter.ErrLoadTenanterFileEmpty) {
223-
glog.Fatalf("LoadCloudConfigsFromFile error %+v", err)
224-
}
225-
glog.Warningf("LoadCloudConfigsFromFile empty file path %s", configFile)
226-
}
227-
228-
glog.Infof("load tenant from file finished")
229-
tenanters, _ = tenanter.GetTenanters(req.Provider)
230-
} else {
231-
tenanters, _ = tenanter.GetTenanters(req.Provider)
221+
//pcm adk过来的请求需要从用户本地读取配置文件
222+
if len(req.RequestSource) > 0 {
223+
tenanter.GenTenanter("configs/config.yaml")
232224
}
233225

226+
tenanters, _ = tenanter.GetTenanters(req.Provider)
227+
234228
//get the available region for product
235229
reqPodRegion := &pbpod.GetPodRegionReq{Provider: req.GetProvider()}
236230
respPodRegion, err := GetPodRegion(ctx, reqPodRegion)

common/tenanter/tenanter.go

+18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package tenanter
22

33
import (
44
"encoding/json"
5+
"flag"
56
"github.com/JCCE-nudt/PCM/lan_trans/idl/pbtenant"
7+
"github.com/golang/glog"
68
"io/ioutil"
79
"os"
810
"sync"
@@ -99,3 +101,19 @@ func GetTenanters(provider pbtenant.CloudProvider) ([]Tenanter, error) {
99101
}
100102
return tenanters, nil
101103
}
104+
105+
func GenTenanter(configPath string) {
106+
var configFile string
107+
flag.StringVar(&configFile, "conf", configPath, "config.yaml")
108+
flag.Parse()
109+
defer glog.Flush()
110+
111+
if err := LoadCloudConfigsFromFile(configFile); err != nil {
112+
if !errors.Is(err, ErrLoadTenanterFileEmpty) {
113+
glog.Fatalf("LoadCloudConfigsFromFile error %+v", err)
114+
}
115+
glog.Warningf("LoadCloudConfigsFromFile empty file path %s", configFile)
116+
}
117+
118+
glog.Infof("load tenant from file finished")
119+
}

idl/pbpod/pod.proto

+7-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ message CreatePodReq {
8181
string vpc_id = 12;
8282
//名空间
8383
string namespace = 13;
84+
//请求源,如果是从pcm sdk 过来的,则单独生成tenanters实体
85+
string requestSource = 14;
8486
}
8587

8688
message CreatePodResp {
@@ -109,6 +111,8 @@ message DeletePodReq {
109111
string namespace = 6;
110112
// 地域,数据中心
111113
int32 region_id = 7;
114+
//请求源,如果是从pcm sdk 过来的,则单独生成tenanters实体
115+
string requestSource = 8;
112116
}
113117

114118
message DeletePodResp {
@@ -149,6 +153,8 @@ message UpdatePodReq {
149153
string restart_policy = 12;
150154
// labels
151155
string labels = 13;
156+
//请求源,如果是从pcm sdk 过来的,则单独生成tenanters实体
157+
string requestSource = 14;
152158
}
153159

154160
message UpdatePodResp {
@@ -204,7 +210,7 @@ message ListPodReq {
204210
pbtenant.CloudProvider provider = 1;
205211
//命名空间
206212
string namespace =2;
207-
//请求源,如果是从ali sdk 过来的,则单独生成tenanters实体
213+
//请求源,如果是从pcm sdk 过来的,则单独生成tenanters实体
208214
string requestSource =3;
209215
}
210216

0 commit comments

Comments
 (0)