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/log"
24 "github.com/apache/servicecomb-service-center/server/core/backend"
25 "github.com/apache/servicecomb-service-center/server/core/proto"
26 "github.com/apache/servicecomb-service-center/server/plugin/pkg/registry"
28 "mepserver/mp1/arch/workspace"
31 type DelOneSubscribe struct {
33 R *http.Request `json:"r,in"`
34 HttpErrInf *proto.Response `json:"httpErrInf,out"`
35 Ctx context.Context `json:"ctx,in"`
36 W http.ResponseWriter `json:"w,in"`
37 AppInstanceId string `json:"appInstanceId,in"`
38 SubscribeId string `json:"subscribeId,in"`
39 HttpRsp interface{} `json:"httpRsp,out"`
42 func (t *DelOneSubscribe) OnRequest(data string) workspace.TaskCode {
44 appInstanceId := t.AppInstanceId
45 subscribeId := t.SubscribeId
47 opts := []registry.PluginOp{
48 registry.OpGet(registry.WithStrKey("/cse-sr/etsi/subscribe/" + appInstanceId + "/" + subscribeId)),
50 resp, errGet := backend.Registry().TxnWithCmp(context.Background(), opts, nil, nil)
52 log.Errorf(errGet, "get subscription from etcd failed")
53 t.SetFirstErrorCode(OperateDataWithEtcdErr, "get subscription from etch failed")
54 return workspace.TaskFinish
57 if len(resp.Kvs) == 0 {
58 log.Errorf(errGet, "subscription not exist")
59 t.SetFirstErrorCode(SubscriptionNotFound, "subscription not exist")
60 return workspace.TaskFinish
63 opts = []registry.PluginOp{
64 registry.OpDel(registry.WithStrKey("/cse-sr/etsi/subscribe/" + appInstanceId + "/" + subscribeId)),
66 _, err := backend.Registry().TxnWithCmp(context.Background(), opts, nil, nil)
68 log.Errorf(err, "delete subscription from etcd failed")
69 t.SetFirstErrorCode(OperateDataWithEtcdErr, "delete subscription from etch failed")
70 return workspace.TaskFinish
74 return workspace.TaskFinish