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.
24 "github.com/apache/servicecomb-service-center/pkg/log"
25 "github.com/apache/servicecomb-service-center/server/core/backend"
26 "github.com/apache/servicecomb-service-center/server/core/proto"
27 "github.com/apache/servicecomb-service-center/server/plugin/pkg/registry"
29 "mepserver/mp1/arch/workspace"
30 "mepserver/mp1/models"
33 type GetOneSubscribe struct {
35 R *http.Request `json:"r,in"`
36 HttpErrInf *proto.Response `json:"httpErrInf,out"`
37 Ctx context.Context `json:"ctx,in"`
38 W http.ResponseWriter `json:"w,in"`
39 AppInstanceId string `json:"appInstanceId,in"`
40 SubscribeId string `json:"subscribeId,in"`
41 HttpRsp interface{} `json:"httpRsp,out"`
44 func (t *GetOneSubscribe) OnRequest(data string) workspace.TaskCode {
46 appInstanceId := t.AppInstanceId
47 subscribeId := t.SubscribeId
49 opts := []registry.PluginOp{
50 registry.OpGet(registry.WithStrKey("/cse-sr/etsi/subscribe/" + appInstanceId + "/" + subscribeId)),
52 resp, err := backend.Registry().TxnWithCmp(context.Background(), opts, nil, nil)
54 log.Errorf(err, "get subscription from etcd failed")
55 t.SetFirstErrorCode(OperateDataWithEtcdErr, "get subscription from etch failed")
56 return workspace.TaskFinish
59 if len(resp.Kvs) == 0 {
60 log.Errorf(err, "subscription not exist")
61 t.SetFirstErrorCode(SubscriptionNotFound, "subscription not exist")
62 return workspace.TaskFinish
64 sub := &models.SerAvailabilityNotificationSubscription{}
65 jsonErr := json.Unmarshal([]byte(string(resp.Kvs[0].Value)), sub)
67 log.Warn("subscribe can not be parsed to SerAvailabilityNotificationSubscription")
68 return workspace.TaskFinish
71 return workspace.TaskFinish