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 GetSubscribes 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 HttpRsp interface{} `json:"httpRsp,out"`
43 func (t *GetSubscribes) OnRequest(data string) workspace.TaskCode {
45 appInstanceId := t.AppInstanceId
47 opts := []registry.PluginOp{
48 registry.OpGet(registry.WithStrKey("/cse-sr/etsi/subscribe/"+appInstanceId), registry.WithPrefix()),
50 resp, err := backend.Registry().TxnWithCmp(context.Background(), opts, nil, nil)
52 log.Errorf(err, "get subscription from etcd failed")
53 t.SetFirstErrorCode(OperateDataWithEtcdErr, "get subscription from etcd failed")
54 return workspace.TaskFinish
58 for _, value := range resp.Kvs {
59 values = append(values, string(value.Value))
62 log.Errorf(err, "get subscription failed, subscription not exist")
63 t.SetFirstErrorCode(SubscriptionNotFound, "get subscription failed, subscription not exist")
64 return workspace.TaskFinish
66 subs := make([]*models.SerAvailabilityNotificationSubscription, 0, len(values))
67 for _, val := range values {
68 sub := &models.SerAvailabilityNotificationSubscription{}
69 err := json.Unmarshal([]byte(val), sub)
71 log.Warn("subscribe can not be parsed to SerAvailabilityNotificationSubscription")
74 subs = append(subs, sub)
77 return workspace.TaskFinish