2 * Copyright 2020 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 "github.com/apache/servicecomb-service-center/pkg/util"
24 "github.com/apache/servicecomb-service-center/server/core"
25 "github.com/apache/servicecomb-service-center/server/core/proto"
27 "mepserver/mp1/arch/workspace"
28 "mepserver/mp1/models"
29 meputil "mepserver/mp1/util"
32 type GetOneDecode struct {
34 R *http.Request `json:"r,in"`
35 Ctx context.Context `json:"ctx,out"`
36 CoreRequest interface{} `json:"coreRequest,out"`
39 func (t *GetOneDecode) OnRequest(data string) workspace.TaskCode {
40 t.Ctx, t.CoreRequest = t.getFindParam(t.R)
41 return workspace.TaskFinish
45 func (t *GetOneDecode) getFindParam(r *http.Request) (context.Context, *proto.GetOneInstanceRequest) {
46 query, ids := meputil.GetHTTPTags(r)
47 mp1SrvId := query.Get(":serviceId")
48 serviceId := mp1SrvId[:len(mp1SrvId)/2]
49 instanceId := mp1SrvId[len(mp1SrvId)/2:]
50 req := &proto.GetOneInstanceRequest{
51 ConsumerServiceId: r.Header.Get("X-ConsumerId"),
52 ProviderServiceId: serviceId,
53 ProviderInstanceId: instanceId,
57 ctx := util.SetTargetDomainProject(r.Context(), r.Header.Get("X-Domain-Name"), query.Get(":project"))
61 type GetOneInstance struct {
63 HttpErrInf *proto.Response `json:"httpErrInf,out"`
64 Ctx context.Context `json:"ctx,in"`
65 CoreRequest interface{} `json:"coreRequest,in"`
66 HttpRsp interface{} `json:"httpRsp,out"`
69 func (t *GetOneInstance) OnRequest(data string) workspace.TaskCode {
70 resp, _ := core.InstanceAPI.GetOneInstance(t.Ctx, t.CoreRequest.(*proto.GetOneInstanceRequest))
71 t.HttpErrInf = resp.Response
73 mp1Rsp := &models.ServiceInfo{}
74 if resp.Instance != nil {
75 mp1Rsp.FromServiceInstance(resp.Instance)
77 t.SetFirstErrorCode(SerInstanceNotFound, "service instance id not found")
78 return workspace.TaskFinish
82 return workspace.TaskFinish