This is an automated email from the ASF dual-hosted git repository.
tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git
The following commit(s) were added to refs/heads/master by this push:
new b9fd84f Change: Remove broker feature (#1116)
b9fd84f is described below
commit b9fd84f387794edd807302e215c874c2feddee23
Author: little-cui <[email protected]>
AuthorDate: Fri Jul 30 16:20:12 2021 +0800
Change: Remove broker feature (#1116)
---
server/bootstrap/bootstrap.go | 4 -
server/broker/broker.go | 30 --
server/broker/broker_key_generator.go | 201 --------
server/broker/broker_suite_test.go | 37 --
server/broker/brokerpb/broker.go | 677 -------------------------
server/broker/config.go | 56 ---
server/broker/controller.go | 200 --------
server/broker/controller_test.go | 51 --
server/broker/service.go | 913 ----------------------------------
server/broker/service_test.go | 244 ---------
server/broker/store.go | 70 ---
server/broker/util.go | 578 ---------------------
12 files changed, 3061 deletions(-)
diff --git a/server/bootstrap/bootstrap.go b/server/bootstrap/bootstrap.go
index 9032ae3..a822538 100644
--- a/server/bootstrap/bootstrap.go
+++ b/server/bootstrap/bootstrap.go
@@ -68,7 +68,6 @@ import (
_ "github.com/apache/servicecomb-service-center/server/job/account"
"github.com/apache/servicecomb-service-center/pkg/log"
- "github.com/apache/servicecomb-service-center/server/broker"
"github.com/apache/servicecomb-service-center/server/handler/accesslog"
"github.com/apache/servicecomb-service-center/server/handler/auth"
"github.com/apache/servicecomb-service-center/server/handler/context"
@@ -98,7 +97,4 @@ func init() {
metrics.RegisterHandlers()
tracing.RegisterHandlers()
route.RegisterHandlers()
-
- // init broker
- broker.Init()
}
diff --git a/server/broker/broker.go b/server/broker/broker.go
deleted file mode 100644
index 0889d77..0000000
--- a/server/broker/broker.go
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package broker
-
-import (
- roa "github.com/apache/servicecomb-service-center/pkg/rest"
-)
-
-func init() {
- registerREST()
-}
-
-func registerREST() {
- roa.RegisterServant(&Controller{})
-}
diff --git a/server/broker/broker_key_generator.go
b/server/broker/broker_key_generator.go
deleted file mode 100644
index 21ef945..0000000
--- a/server/broker/broker_key_generator.go
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package broker
-
-import (
- "strconv"
-
- "github.com/apache/servicecomb-service-center/pkg/util"
-)
-
-const (
- BrokerRootKey = "cse-pact"
- BrokerParticipantKey = "participant"
- BrokerVersionKey = "version"
- BrokerPactKey = "pact"
- BrokerPactVersionKey = "pact-version"
- BrokerPactTagKey = "pact-tag"
- BrokerPactVerificationKey = "verification"
- BrokerPactLatest = "latest"
-)
-
-// GetBrokerRootKey returns url (/cse-pact)
-func GetBrokerRootKey() string {
- return util.StringJoin([]string{
- "",
- BrokerRootKey,
- }, "/")
-}
-
-//GetBrokerLatestKey returns pact related keys
-func GetBrokerLatestKey(tenant string) string {
- return util.StringJoin([]string{
- GetBrokerRootKey(),
- BrokerPactLatest,
- tenant,
- }, "/")
-}
-
-//GetBrokerParticipantKey returns the participant root key
-func GetBrokerParticipantKey(tenant string) string {
- return util.StringJoin([]string{
- GetBrokerRootKey(),
- BrokerParticipantKey,
- tenant,
- }, "/")
-}
-
-//GenerateBrokerParticipantKey returns the participant key
-func GenerateBrokerParticipantKey(tenant string, appID string, serviceName
string) string {
- return util.StringJoin([]string{
- GetBrokerParticipantKey(tenant),
- appID,
- serviceName,
- }, "/")
-}
-
-//GetBrokerVersionKey returns th root version key
-func GetBrokerVersionKey(tenant string) string {
- return util.StringJoin([]string{
- GetBrokerRootKey(),
- BrokerVersionKey,
- tenant,
- }, "/")
-}
-
-//GenerateBrokerVersionKey returns the version key
-func GenerateBrokerVersionKey(tenant string, number string, participantID
int32) string {
- return util.StringJoin([]string{
- GetBrokerVersionKey(tenant),
- number,
- strconv.Itoa(int(participantID)),
- }, "/")
-}
-
-//GetBrokerPactKey returns the pact root key
-func GetBrokerPactKey(tenant string) string {
- return util.StringJoin([]string{
- GetBrokerRootKey(),
- BrokerPactKey,
- tenant,
- }, "/")
-}
-
-//GenerateBrokerPactKey returns the pact key
-func GenerateBrokerPactKey(tenant string, consumerParticipantID int32,
- providerParticipantID int32, sha []byte) string {
- return util.StringJoin([]string{
- GetBrokerPactKey(tenant),
- strconv.Itoa(int(consumerParticipantID)),
- strconv.Itoa(int(providerParticipantID)),
- string(sha),
- }, "/")
-}
-
-//GetBrokerPactVersionKey returns the pact version root key
-func GetBrokerPactVersionKey(tenant string) string {
- return util.StringJoin([]string{
- GetBrokerRootKey(),
- BrokerPactVersionKey,
- tenant,
- }, "/")
-}
-
-//GenerateBrokerPactVersionKey returns the pact version root key
-func GenerateBrokerPactVersionKey(tenant string, versionID int32, pactID
int32) string {
- return util.StringJoin([]string{
- GetBrokerPactVersionKey(tenant),
- strconv.Itoa(int(versionID)),
- strconv.Itoa(int(pactID)),
- }, "/")
-}
-
-//GetBrokerTagKey returns the broker tag root key
-func GetBrokerTagKey(tenant string) string {
- return util.StringJoin([]string{
- GetBrokerRootKey(),
- BrokerPactTagKey,
- tenant,
- }, "/")
-}
-
-//GenerateBrokerTagKey returns the broker tag key
-func GenerateBrokerTagKey(tenant string, versionID int32) string {
- return util.StringJoin([]string{
- GetBrokerTagKey(tenant),
- strconv.Itoa(int(versionID)),
- }, "/")
-}
-
-//GetBrokerVerificationKey returns the verification root key
-func GetBrokerVerificationKey(tenant string) string {
- return util.StringJoin([]string{
- GetBrokerRootKey(),
- BrokerPactVerificationKey,
- tenant,
- }, "/")
-}
-
-//GenerateBrokerVerificationKey returns he verification key
-func GenerateBrokerVerificationKey(tenant string, pactVersionID int32, number
int32) string {
- return util.StringJoin([]string{
- GetBrokerVerificationKey(tenant),
- strconv.Itoa(int(pactVersionID)),
- strconv.Itoa(int(number)),
- }, "/")
-}
-
-//GetBrokerLatestParticipantIDKey returns the latest participant ID
-func GetBrokerLatestParticipantIDKey() string {
- return util.StringJoin([]string{
- GetBrokerLatestKey("default"),
- BrokerParticipantKey,
- }, "/")
-}
-
-//GetBrokerLatestVersionIDKey returns latest version ID
-func GetBrokerLatestVersionIDKey() string {
- return util.StringJoin([]string{
- GetBrokerLatestKey("default"),
- BrokerVersionKey,
- }, "/")
-}
-
-//GetBrokerLatestPactIDKey returns latest pact ID
-func GetBrokerLatestPactIDKey() string {
- return util.StringJoin([]string{
- GetBrokerLatestKey("default"),
- BrokerPactKey,
- }, "/")
-}
-
-//GetBrokerLatestPactVersionIDKey returns lated pact version ID
-func GetBrokerLatestPactVersionIDKey() string {
- return util.StringJoin([]string{
- GetBrokerLatestKey("default"),
- BrokerPactVersionKey,
- }, "/")
-}
-
-//GetBrokerLatestVerificationIDKey returns the lastest verification ID
-func GetBrokerLatestVerificationIDKey() string {
- return util.StringJoin([]string{
- GetBrokerLatestKey("default"),
- BrokerPactVerificationKey,
- }, "/")
-}
diff --git a/server/broker/broker_suite_test.go
b/server/broker/broker_suite_test.go
deleted file mode 100644
index 17accdf..0000000
--- a/server/broker/broker_suite_test.go
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package broker_test
-
-import (
- "github.com/apache/servicecomb-service-center/server/broker"
- _ "github.com/apache/servicecomb-service-center/test"
-
- . "github.com/onsi/ginkgo"
- "github.com/onsi/ginkgo/reporters"
-
- "testing"
-
- . "github.com/onsi/gomega"
-)
-
-var brokerResource = broker.ServiceAPI
-
-func TestBroker(t *testing.T) {
- RegisterFailHandler(Fail)
- junitReporter := reporters.NewJUnitReporter("model.junit.xml")
- RunSpecsWithDefaultAndCustomReporters(t, "model Suite",
[]Reporter{junitReporter})
-}
diff --git a/server/broker/brokerpb/broker.go b/server/broker/brokerpb/broker.go
deleted file mode 100644
index f86a5de..0000000
--- a/server/broker/brokerpb/broker.go
+++ /dev/null
@@ -1,677 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package brokerpb
-
-import (
- "github.com/go-chassis/cari/discovery"
-)
-
-type Participant struct {
- Id int32 `protobuf:"varint,1,opt,name=id" json:"id,omitempty"`
- AppId string `protobuf:"bytes,2,opt,name=appId"
json:"appId,omitempty"`
- ServiceName string `protobuf:"bytes,3,opt,name=serviceName"
json:"serviceName,omitempty"`
-}
-
-func (m *Participant) Reset() { *m = Participant{} }
-
-func (m *Participant) GetId() int32 {
- if m != nil {
- return m.Id
- }
- return 0
-}
-
-func (m *Participant) GetAppId() string {
- if m != nil {
- return m.AppId
- }
- return ""
-}
-
-func (m *Participant) GetServiceName() string {
- if m != nil {
- return m.ServiceName
- }
- return ""
-}
-
-type Version struct {
- Id int32 `protobuf:"varint,1,opt,name=id"
json:"id,omitempty"`
- Number string `protobuf:"bytes,2,opt,name=number"
json:"number,omitempty"`
- ParticipantId int32 `protobuf:"varint,3,opt,name=participantId"
json:"participantId,omitempty"`
- Order int32 `protobuf:"varint,4,opt,name=order"
json:"order,omitempty"`
-}
-
-func (m *Version) Reset() { *m = Version{} }
-
-func (m *Version) GetId() int32 {
- if m != nil {
- return m.Id
- }
- return 0
-}
-
-func (m *Version) GetNumber() string {
- if m != nil {
- return m.Number
- }
- return ""
-}
-
-func (m *Version) GetParticipantId() int32 {
- if m != nil {
- return m.ParticipantId
- }
- return 0
-}
-
-func (m *Version) GetOrder() int32 {
- if m != nil {
- return m.Order
- }
- return 0
-}
-
-type Pact struct {
- Id int32 `protobuf:"varint,1,opt,name=id"
json:"id,omitempty"`
- ConsumerParticipantId int32
`protobuf:"varint,2,opt,name=consumerParticipantId"
json:"consumerParticipantId,omitempty"`
- ProviderParticipantId int32
`protobuf:"varint,3,opt,name=providerParticipantId"
json:"providerParticipantId,omitempty"`
- Sha []byte `protobuf:"bytes,4,opt,name=sha,proto3"
json:"sha,omitempty"`
- Content []byte
`protobuf:"bytes,5,opt,name=content,proto3" json:"content,omitempty"`
-}
-
-func (m *Pact) Reset() { *m = Pact{} }
-
-func (m *Pact) GetId() int32 {
- if m != nil {
- return m.Id
- }
- return 0
-}
-
-func (m *Pact) GetConsumerParticipantId() int32 {
- if m != nil {
- return m.ConsumerParticipantId
- }
- return 0
-}
-
-func (m *Pact) GetProviderParticipantId() int32 {
- if m != nil {
- return m.ProviderParticipantId
- }
- return 0
-}
-
-func (m *Pact) GetSha() []byte {
- if m != nil {
- return m.Sha
- }
- return nil
-}
-
-func (m *Pact) GetContent() []byte {
- if m != nil {
- return m.Content
- }
- return nil
-}
-
-type PactVersion struct {
- Id int32 `protobuf:"varint,1,opt,name=id"
json:"id,omitempty"`
- VersionId int32 `protobuf:"varint,2,opt,name=versionId"
json:"versionId,omitempty"`
- PactId int32 `protobuf:"varint,3,opt,name=pactId"
json:"pactId,omitempty"`
- ProviderParticipantId int32
`protobuf:"varint,4,opt,name=providerParticipantId"
json:"providerParticipantId,omitempty"`
-}
-
-func (m *PactVersion) Reset() { *m = PactVersion{} }
-
-func (m *PactVersion) GetId() int32 {
- if m != nil {
- return m.Id
- }
- return 0
-}
-
-func (m *PactVersion) GetVersionId() int32 {
- if m != nil {
- return m.VersionId
- }
- return 0
-}
-
-func (m *PactVersion) GetPactId() int32 {
- if m != nil {
- return m.PactId
- }
- return 0
-}
-
-func (m *PactVersion) GetProviderParticipantId() int32 {
- if m != nil {
- return m.ProviderParticipantId
- }
- return 0
-}
-
-type Tag struct {
- Name string `protobuf:"bytes,1,opt,name=name"
json:"name,omitempty"`
- VersionId int32 `protobuf:"varint,2,opt,name=versionId"
json:"versionId,omitempty"`
-}
-
-func (m *Tag) Reset() { *m = Tag{} }
-
-func (m *Tag) GetName() string {
- if m != nil {
- return m.Name
- }
- return ""
-}
-
-func (m *Tag) GetVersionId() int32 {
- if m != nil {
- return m.VersionId
- }
- return 0
-}
-
-type PublishPactRequest struct {
- ProviderId string `protobuf:"bytes,1,opt,name=providerId"
json:"providerId,omitempty"`
- ConsumerId string `protobuf:"bytes,2,opt,name=consumerId"
json:"consumerId,omitempty"`
- Version string `protobuf:"bytes,3,opt,name=version"
json:"version,omitempty"`
- Pact []byte `protobuf:"bytes,4,opt,name=pact,proto3"
json:"pact,omitempty"`
-}
-
-func (m *PublishPactRequest) Reset() { *m = PublishPactRequest{} }
-
-func (m *PublishPactRequest) GetProviderId() string {
- if m != nil {
- return m.ProviderId
- }
- return ""
-}
-
-func (m *PublishPactRequest) GetConsumerId() string {
- if m != nil {
- return m.ConsumerId
- }
- return ""
-}
-
-func (m *PublishPactRequest) GetPact() []byte {
- if m != nil {
- return m.Pact
- }
- return nil
-}
-
-type PublishPactResponse struct {
- Response *discovery.Response `protobuf:"bytes,1,opt,name=response"
json:"-"`
-}
-
-func (m *PublishPactResponse) Reset() { *m = PublishPactResponse{} }
-
-type GetAllProviderPactsRequest struct {
- ProviderId string `protobuf:"bytes,1,opt,name=providerId"
json:"providerId,omitempty"`
- BaseUrl *BaseBrokerRequest `protobuf:"bytes,2,opt,name=baseUrl"
json:"baseUrl,omitempty"`
-}
-
-func (m *GetAllProviderPactsRequest) Reset() { *m =
GetAllProviderPactsRequest{} }
-
-func (m *GetAllProviderPactsRequest) GetProviderId() string {
- if m != nil {
- return m.ProviderId
- }
- return ""
-}
-
-func (m *GetAllProviderPactsRequest) GetBaseUrl() *BaseBrokerRequest {
- if m != nil {
- return m.BaseUrl
- }
- return nil
-}
-
-type ConsumerInfo struct {
- Href string `protobuf:"bytes,1,opt,name=href" json:"href,omitempty"`
- Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
-}
-
-func (m *ConsumerInfo) GetHref() string {
- if m != nil {
- return m.Href
- }
- return ""
-}
-
-func (m *ConsumerInfo) GetName() string {
- if m != nil {
- return m.Name
- }
- return ""
-}
-
-type Links struct {
- Pacts []*ConsumerInfo `protobuf:"bytes,1,rep,name=pacts"
json:"pacts,omitempty"`
-}
-
-func (m *Links) Reset() { *m = Links{} }
-
-func (m *Links) GetPacts() []*ConsumerInfo {
- if m != nil {
- return m.Pacts
- }
- return nil
-}
-
-type GetAllProviderPactsResponse struct {
- Response *discovery.Response `protobuf:"bytes,1,opt,name=response"
json:"-"`
- XLinks *Links
`protobuf:"bytes,2,opt,name=_links,json=Links" json:"_links,omitempty"`
-}
-
-func (m *GetAllProviderPactsResponse) Reset() { *m =
GetAllProviderPactsResponse{} }
-
-func (m *GetAllProviderPactsResponse) GetXLinks() *Links {
- if m != nil {
- return m.XLinks
- }
- return nil
-}
-
-type GetProviderConsumerVersionPactRequest struct {
- ProviderId string `protobuf:"bytes,1,opt,name=providerId"
json:"providerId,omitempty"`
- ConsumerId string `protobuf:"bytes,2,opt,name=consumerId"
json:"consumerId,omitempty"`
- Version string `protobuf:"bytes,3,opt,name=version"
json:"version,omitempty"`
- BaseUrl *BaseBrokerRequest `protobuf:"bytes,4,opt,name=baseUrl"
json:"baseUrl,omitempty"`
-}
-
-func (m *GetProviderConsumerVersionPactRequest) Reset() { *m =
GetProviderConsumerVersionPactRequest{} }
-
-func (m *GetProviderConsumerVersionPactRequest) GetProviderId() string {
- if m != nil {
- return m.ProviderId
- }
- return ""
-}
-
-func (m *GetProviderConsumerVersionPactRequest) GetConsumerId() string {
- if m != nil {
- return m.ConsumerId
- }
- return ""
-}
-
-func (m *GetProviderConsumerVersionPactRequest) GetBaseUrl()
*BaseBrokerRequest {
- if m != nil {
- return m.BaseUrl
- }
- return nil
-}
-
-type GetProviderConsumerVersionPactResponse struct {
- Response *discovery.Response `protobuf:"bytes,1,opt,name=response"
json:"-"`
- Pact []byte `protobuf:"bytes,2,opt,name=pact,proto3"
json:"pact,omitempty"`
-}
-
-func (m *GetProviderConsumerVersionPactResponse) Reset() {
- *m = GetProviderConsumerVersionPactResponse{}
-}
-
-func (m *GetProviderConsumerVersionPactResponse) GetPact() []byte {
- if m != nil {
- return m.Pact
- }
- return nil
-}
-
-type Verification struct {
- Id int32 `protobuf:"varint,1,opt,name=id"
json:"id,omitempty"`
- Number int32 `protobuf:"varint,2,opt,name=number"
json:"number,omitempty"`
- PactVersionId int32 `protobuf:"varint,3,opt,name=pactVersionId"
json:"pactVersionId,omitempty"`
- Success bool `protobuf:"varint,4,opt,name=success"
json:"success,omitempty"`
- ProviderVersion string `protobuf:"bytes,5,opt,name=providerVersion"
json:"providerVersion,omitempty"`
- BuildUrl string `protobuf:"bytes,6,opt,name=buildUrl"
json:"buildUrl,omitempty"`
- VerificationDate string `protobuf:"bytes,7,opt,name=verificationDate"
json:"verificationDate,omitempty"`
-}
-
-func (m *Verification) Reset() { *m = Verification{} }
-
-func (m *Verification) GetId() int32 {
- if m != nil {
- return m.Id
- }
- return 0
-}
-
-func (m *Verification) GetNumber() int32 {
- if m != nil {
- return m.Number
- }
- return 0
-}
-
-func (m *Verification) GetPactVersionId() int32 {
- if m != nil {
- return m.PactVersionId
- }
- return 0
-}
-
-func (m *Verification) GetSuccess() bool {
- if m != nil {
- return m.Success
- }
- return false
-}
-
-func (m *Verification) GetProviderVersion() string {
- if m != nil {
- return m.ProviderVersion
- }
- return ""
-}
-
-func (m *Verification) GetBuildUrl() string {
- if m != nil {
- return m.BuildUrl
- }
- return ""
-}
-
-func (m *Verification) GetVerificationDate() string {
- if m != nil {
- return m.VerificationDate
- }
- return ""
-}
-
-type VerificationSummary struct {
- Successful []string `protobuf:"bytes,1,rep,name=successful"
json:"successful,omitempty"`
- Failed []string `protobuf:"bytes,2,rep,name=failed"
json:"failed,omitempty"`
- Unknown []string `protobuf:"bytes,3,rep,name=unknown"
json:"unknown,omitempty"`
-}
-
-func (m *VerificationSummary) Reset() { *m = VerificationSummary{} }
-
-func (m *VerificationSummary) GetSuccessful() []string {
- if m != nil {
- return m.Successful
- }
- return nil
-}
-
-func (m *VerificationSummary) GetFailed() []string {
- if m != nil {
- return m.Failed
- }
- return nil
-}
-
-func (m *VerificationSummary) GetUnknown() []string {
- if m != nil {
- return m.Unknown
- }
- return nil
-}
-
-type VerificationDetail struct {
- ProviderName string
`protobuf:"bytes,1,opt,name=providerName" json:"providerName,omitempty"`
- ProviderApplicationVersion string
`protobuf:"bytes,2,opt,name=providerApplicationVersion"
json:"providerApplicationVersion,omitempty"`
- Success bool `protobuf:"varint,3,opt,name=success"
json:"success,omitempty"`
- VerificationDate string
`protobuf:"bytes,4,opt,name=verificationDate" json:"verificationDate,omitempty"`
-}
-
-func (m *VerificationDetail) Reset() { *m = VerificationDetail{} }
-
-func (m *VerificationDetail) GetProviderName() string {
- if m != nil {
- return m.ProviderName
- }
- return ""
-}
-
-func (m *VerificationDetail) GetProviderApplicationVersion() string {
- if m != nil {
- return m.ProviderApplicationVersion
- }
- return ""
-}
-
-func (m *VerificationDetail) GetSuccess() bool {
- if m != nil {
- return m.Success
- }
- return false
-}
-
-func (m *VerificationDetail) GetVerificationDate() string {
- if m != nil {
- return m.VerificationDate
- }
- return ""
-}
-
-type VerificationDetails struct {
- VerificationResults []*VerificationDetail
`protobuf:"bytes,1,rep,name=verificationResults"
json:"verificationResults,omitempty"`
-}
-
-func (m *VerificationDetails) GetVerificationResults() []*VerificationDetail {
- if m != nil {
- return m.VerificationResults
- }
- return nil
-}
-
-type VerificationResult struct {
- Success bool
`protobuf:"varint,1,opt,name=success" json:"success,omitempty"`
- ProviderSummary *VerificationSummary
`protobuf:"bytes,2,opt,name=providerSummary" json:"providerSummary,omitempty"`
- XEmbedded *VerificationDetails
`protobuf:"bytes,3,opt,name=_embedded,json=Embedded" json:"_embedded,omitempty"`
-}
-
-func (m *VerificationResult) Reset() { *m = VerificationResult{} }
-
-func (m *VerificationResult) GetSuccess() bool {
- if m != nil {
- return m.Success
- }
- return false
-}
-
-func (m *VerificationResult) GetProviderSummary() *VerificationSummary {
- if m != nil {
- return m.ProviderSummary
- }
- return nil
-}
-
-func (m *VerificationResult) GetXEmbedded() *VerificationDetails {
- if m != nil {
- return m.XEmbedded
- }
- return nil
-}
-
-type PublishVerificationRequest struct {
- ProviderId string
`protobuf:"bytes,1,opt,name=providerId" json:"providerId,omitempty"`
- ConsumerId string
`protobuf:"bytes,2,opt,name=consumerId" json:"consumerId,omitempty"`
- PactId int32 `protobuf:"varint,3,opt,name=pactId"
json:"pactId,omitempty"`
- Success bool `protobuf:"varint,4,opt,name=success"
json:"success,omitempty"`
- ProviderApplicationVersion string
`protobuf:"bytes,5,opt,name=providerApplicationVersion"
json:"providerApplicationVersion,omitempty"`
-}
-
-func (m *PublishVerificationRequest) Reset() { *m =
PublishVerificationRequest{} }
-
-func (m *PublishVerificationRequest) GetProviderId() string {
- if m != nil {
- return m.ProviderId
- }
- return ""
-}
-
-func (m *PublishVerificationRequest) GetConsumerId() string {
- if m != nil {
- return m.ConsumerId
- }
- return ""
-}
-
-func (m *PublishVerificationRequest) GetPactId() int32 {
- if m != nil {
- return m.PactId
- }
- return 0
-}
-
-func (m *PublishVerificationRequest) GetSuccess() bool {
- if m != nil {
- return m.Success
- }
- return false
-}
-
-func (m *PublishVerificationRequest) GetProviderApplicationVersion() string {
- if m != nil {
- return m.ProviderApplicationVersion
- }
- return ""
-}
-
-type PublishVerificationResponse struct {
- Response *discovery.Response `protobuf:"bytes,1,opt,name=response"
json:"-"`
- Confirmation *VerificationDetail
`protobuf:"bytes,2,opt,name=confirmation" json:"confirmation,omitempty"`
-}
-
-func (m *PublishVerificationResponse) GetConfirmation() *VerificationDetail {
- if m != nil {
- return m.Confirmation
- }
- return nil
-}
-
-type RetrieveVerificationRequest struct {
- ConsumerId string `protobuf:"bytes,1,opt,name=consumerId"
json:"consumerId,omitempty"`
- ConsumerVersion string `protobuf:"bytes,2,opt,name=consumerVersion"
json:"consumerVersion,omitempty"`
-}
-
-func (m *RetrieveVerificationRequest) Reset() { *m =
RetrieveVerificationRequest{} }
-
-func (m *RetrieveVerificationRequest) GetConsumerId() string {
- if m != nil {
- return m.ConsumerId
- }
- return ""
-}
-
-func (m *RetrieveVerificationRequest) GetConsumerVersion() string {
- if m != nil {
- return m.ConsumerVersion
- }
- return ""
-}
-
-type RetrieveVerificationResponse struct {
- Response *discovery.Response `protobuf:"bytes,1,opt,name=response"
json:"-"`
- Result *VerificationResult `protobuf:"bytes,2,opt,name=result"
json:"result,omitempty"`
-}
-
-func (m *RetrieveVerificationResponse) Reset() { *m =
RetrieveVerificationResponse{} }
-
-func (m *RetrieveVerificationResponse) GetResult() *VerificationResult {
- if m != nil {
- return m.Result
- }
- return nil
-}
-
-type BaseBrokerRequest struct {
- HostAddress string `protobuf:"bytes,1,opt,name=hostAddress"
json:"hostAddress,omitempty"`
- Scheme string `protobuf:"bytes,2,opt,name=scheme"
json:"scheme,omitempty"`
-}
-
-func (m *BaseBrokerRequest) Reset() { *m = BaseBrokerRequest{} }
-
-func (m *BaseBrokerRequest) GetHostAddress() string {
- if m != nil {
- return m.HostAddress
- }
- return ""
-}
-
-func (m *BaseBrokerRequest) GetScheme() string {
- if m != nil {
- return m.Scheme
- }
- return ""
-}
-
-type BrokerAPIInfoEntry struct {
- Href string `protobuf:"bytes,1,opt,name=href"
json:"href,omitempty"`
- Name string `protobuf:"bytes,2,opt,name=name"
json:"name,omitempty"`
- Title string `protobuf:"bytes,3,opt,name=title"
json:"title,omitempty"`
- Templated bool `protobuf:"varint,4,opt,name=templated"
json:"templated,omitempty"`
-}
-
-func (m *BrokerAPIInfoEntry) GetHref() string {
- if m != nil {
- return m.Href
- }
- return ""
-}
-
-func (m *BrokerAPIInfoEntry) GetName() string {
- if m != nil {
- return m.Name
- }
- return ""
-}
-
-func (m *BrokerAPIInfoEntry) GetTitle() string {
- if m != nil {
- return m.Title
- }
- return ""
-}
-
-func (m *BrokerAPIInfoEntry) GetTemplated() bool {
- if m != nil {
- return m.Templated
- }
- return false
-}
-
-type BrokerHomeResponse struct {
- Response *discovery.Response
`protobuf:"bytes,1,opt,name=response" json:"-"`
- XLinks map[string]*BrokerAPIInfoEntry
`protobuf:"bytes,2,rep,name=_links,json=Links" json:"_links,omitempty"
protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
- Curies []*BrokerAPIInfoEntry
`protobuf:"bytes,3,rep,name=curies" json:"curies,omitempty"`
-}
-
-func (m *BrokerHomeResponse) Reset() { *m = BrokerHomeResponse{} }
-
-func (m *BrokerHomeResponse) GetXLinks() map[string]*BrokerAPIInfoEntry {
- if m != nil {
- return m.XLinks
- }
- return nil
-}
-
-func (m *BrokerHomeResponse) GetCuries() []*BrokerAPIInfoEntry {
- if m != nil {
- return m.Curies
- }
- return nil
-}
diff --git a/server/broker/config.go b/server/broker/config.go
deleted file mode 100644
index 23e125b..0000000
--- a/server/broker/config.go
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package broker
-
-import (
- "path/filepath"
-
- "github.com/apache/servicecomb-service-center/datasource/etcd/kv"
- "github.com/apache/servicecomb-service-center/datasource/etcd/sd"
- "github.com/apache/servicecomb-service-center/pkg/log"
- "github.com/apache/servicecomb-service-center/server/config"
-)
-
-func Init() {
- //define Broker logger
- name := ""
- if len(config.GetLog().LogFilePath) != 0 {
- name = filepath.Join(filepath.Dir(config.GetLog().LogFilePath),
"broker_srvc.log")
- }
- PactLogger = log.NewLogger(log.Config{
- LoggerLevel: config.GetLog().LogLevel,
- LoggerFile: name,
- LogFormatText: config.GetLog().LogFormat == "text",
- LogRotateSize: int(config.GetLog().LogRotateSize),
- LogBackupCount: int(config.GetLog().LogBackupCount),
- })
- PARTICIPANT = kv.Store().MustInstall(kv.NewAddOn("PARTICIPANT",
- sd.Configure().WithPrefix(GetBrokerParticipantKey(""))))
- VERSION = kv.Store().MustInstall(kv.NewAddOn("VERSION",
- sd.Configure().WithPrefix(GetBrokerVersionKey(""))))
- PACT = kv.Store().MustInstall(kv.NewAddOn("PACT",
- sd.Configure().WithPrefix(GetBrokerPactKey(""))))
- PactVersion = kv.Store().MustInstall(kv.NewAddOn("PACT_VERSION",
- sd.Configure().WithPrefix(GetBrokerPactVersionKey(""))))
- PactTag = kv.Store().MustInstall(kv.NewAddOn("PACT_TAG",
- sd.Configure().WithPrefix(GetBrokerTagKey(""))))
- VERIFICATION = kv.Store().MustInstall(kv.NewAddOn("VERIFICATION",
- sd.Configure().WithPrefix(GetBrokerVerificationKey(""))))
- PactLatest = kv.Store().MustInstall(kv.NewAddOn("PACT_LATEST",
- sd.Configure().WithPrefix(GetBrokerLatestKey(""))))
-}
diff --git a/server/broker/controller.go b/server/broker/controller.go
deleted file mode 100644
index 2981c87..0000000
--- a/server/broker/controller.go
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package broker
-
-import (
- "encoding/json"
- "io/ioutil"
- "net/http"
- "strconv"
-
- "github.com/apache/servicecomb-service-center/pkg/log"
-
- "github.com/apache/servicecomb-service-center/pkg/rest"
- "github.com/apache/servicecomb-service-center/server/broker/brokerpb"
- pb "github.com/go-chassis/cari/discovery"
-)
-
-const DefaultScheme = "http"
-
-type Controller struct {
-}
-
-func (brokerService *Controller) URLPatterns() []rest.Route {
- return []rest.Route{
- // for handling broker requests
- {Method: http.MethodGet,
- Path: "/",
- Func: brokerService.GetHome},
- {Method: http.MethodPut,
- Path:
"/pacts/provider/:providerId/consumer/:consumerId/version/:number",
- Func: brokerService.PublishPact},
- {Method: http.MethodGet,
- Path: "/pacts/provider/:providerId/latest",
- Func: brokerService.GetAllProviderPacts},
- {Method: http.MethodGet,
- Path:
"/pacts/provider/:providerId/consumer/:consumerId/version/:number",
- Func: brokerService.GetPactsOfProvider},
- {Method: http.MethodDelete,
- Path: "/pacts/delete",
- Func: brokerService.DeletePacts},
- {Method: http.MethodPost,
- Path:
"/pacts/provider/:providerId/consumer/:consumerId/pact-version/:sha/verification-results",
- Func: brokerService.PublishVerificationResults},
- {Method: http.MethodGet,
- Path:
"/verification-results/consumer/:consumerId/version/:consumerVersion/latest",
- Func: brokerService.RetrieveVerificationResults},
- }
-}
-
-func (brokerService *Controller) GetHome(w http.ResponseWriter, r
*http.Request) {
- request := &brokerpb.BaseBrokerRequest{
- HostAddress: r.Host,
- Scheme: getScheme(r),
- }
- resp, _ := ServiceAPI.GetBrokerHome(r.Context(), request)
- rest.WriteResponse(w, r, resp.Response, resp)
-}
-
-func (*Controller) PublishPact(w http.ResponseWriter, r *http.Request) {
- message, err := ioutil.ReadAll(r.Body)
- if err != nil {
- PactLogger.Error("body err\n", err)
- rest.WriteError(w, pb.ErrInvalidParams, err.Error())
- return
- }
- query := r.URL.Query()
- request := &brokerpb.PublishPactRequest{
- ProviderId: query.Get(":providerId"),
- ConsumerId: query.Get(":consumerId"),
- Version: query.Get(":number"),
- Pact: message,
- }
- PactLogger.Infof("PublishPact: providerId = %s, consumerId = %s,
version = %s\n",
- request.ProviderId, request.ConsumerId, request.Version)
- resp, err := ServiceAPI.PublishPact(r.Context(), request)
- if err != nil {
- log.Errorf(err, "can not push pact")
- rest.WriteError(w, pb.ErrInternal, "can not push pact")
- return
- }
- rest.WriteResponse(w, r, resp.Response, resp)
-}
-
-func (*Controller) GetAllProviderPacts(w http.ResponseWriter, r *http.Request)
{
- request := &brokerpb.GetAllProviderPactsRequest{
- ProviderId: r.URL.Query().Get(":providerId"),
- BaseUrl: &brokerpb.BaseBrokerRequest{
- HostAddress: r.Host,
- Scheme: getScheme(r),
- },
- }
- resp, err := ServiceAPI.GetAllProviderPacts(r.Context(), request /*,
href*/)
- if err != nil {
- PactLogger.Errorf(err, "can not get pacts")
- rest.WriteError(w, pb.ErrInternal, "can not get pacts")
- return
- }
- linksObj, err := json.Marshal(resp)
- if err != nil {
- PactLogger.Errorf(err, "invalid ProviderPacts")
- rest.WriteError(w, pb.ErrInternal, "Marshal error")
- return
- }
- PactLogger.Infof("Pact info: %s\n", string(linksObj))
- rest.WriteResponse(w, r, resp.Response, resp)
-}
-
-func (*Controller) GetPactsOfProvider(w http.ResponseWriter, r *http.Request) {
- query := r.URL.Query()
- request := &brokerpb.GetProviderConsumerVersionPactRequest{
- ProviderId: query.Get(":providerId"),
- ConsumerId: query.Get(":consumerId"),
- Version: query.Get(":number"),
- BaseUrl: &brokerpb.BaseBrokerRequest{
- HostAddress: r.Host,
- Scheme: getScheme(r),
- },
- }
-
- resp, _ := ServiceAPI.GetPactsOfProvider(r.Context(), request)
- rest.WriteResponse(w, r, resp.Response, resp.Pact)
-}
-
-func (*Controller) DeletePacts(w http.ResponseWriter, r *http.Request) {
- resp, _ := ServiceAPI.DeletePacts(r.Context(),
&brokerpb.BaseBrokerRequest{
- HostAddress: r.Host,
- Scheme: getScheme(r),
- })
- rest.WriteResponse(w, r, resp, nil)
-}
-
-func (*Controller) PublishVerificationResults(w http.ResponseWriter, r
*http.Request) {
- requestBody, err := ioutil.ReadAll(r.Body)
- if err != nil {
- PactLogger.Error("body err", err)
- rest.WriteError(w, pb.ErrInvalidParams, err.Error())
- return
- }
- request := &brokerpb.PublishVerificationRequest{}
- err = json.Unmarshal(requestBody, request)
- if err != nil {
- PactLogger.Error("Unmarshal error", err)
- rest.WriteError(w, pb.ErrInvalidParams, err.Error())
- return
- }
- query := r.URL.Query()
- request.ProviderId = query.Get(":providerId")
- request.ConsumerId = query.Get(":consumerId")
- i, err := strconv.ParseInt(query.Get(":sha"), 10, 32)
- if err != nil {
- PactLogger.Error("Invalid pactId", err)
- rest.WriteError(w, pb.ErrInvalidParams, err.Error())
- return
- }
- request.PactId = int32(i)
- PactLogger.Infof("PublishVerificationResults: %s, %s, %d, %t, %s\n",
- request.ProviderId, request.ConsumerId, request.PactId,
request.Success,
- request.ProviderApplicationVersion)
- resp, err := ServiceAPI.PublishVerificationResults(r.Context(),
- request)
- if err != nil {
- PactLogger.Error("publish failed", err)
- rest.WriteError(w, pb.ErrInternal, "publish failed")
- return
- }
- rest.WriteResponse(w, r, resp.Response, resp)
-}
-
-func (*Controller) RetrieveVerificationResults(w http.ResponseWriter, r
*http.Request) {
- request := &brokerpb.RetrieveVerificationRequest{}
- query := r.URL.Query()
- request.ConsumerId = query.Get(":consumerId")
- request.ConsumerVersion = query.Get(":consumerVersion")
- PactLogger.Infof("Retrieve verification results for: %s, %s\n",
- request.ConsumerId, request.ConsumerVersion)
- resp, _ := ServiceAPI.RetrieveVerificationResults(r.Context(), request)
- rest.WriteResponse(w, r, resp.Response, resp)
-}
-
-func getScheme(r *http.Request) string {
- if len(r.URL.Scheme) < 1 {
- return DefaultScheme
- }
- return r.URL.Scheme
-}
diff --git a/server/broker/controller_test.go b/server/broker/controller_test.go
deleted file mode 100644
index abd7c3c..0000000
--- a/server/broker/controller_test.go
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package broker_test
-
-import (
- "bytes"
- "net/http"
- "net/http/httptest"
- "testing"
-
- . "github.com/apache/servicecomb-service-center/server/broker"
-)
-
-var (
- ctrl = &Controller{}
- num int
-)
-
-type mockBrokerHandler struct {
-}
-
-func (b *mockBrokerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- route := ctrl.URLPatterns()[num]
- r.Method = route.Method
- r.URL.RawQuery = ":sha=1"
- route.Func(w, r)
- num++
-}
-
-func TestBrokerController_GetHome(t *testing.T) {
- svr := httptest.NewServer(&mockBrokerHandler{})
- defer svr.Close()
-
- for range ctrl.URLPatterns() {
- http.Post(svr.URL, "application/json",
bytes.NewBuffer([]byte("{}")))
- }
-}
diff --git a/server/broker/service.go b/server/broker/service.go
deleted file mode 100644
index 58eec98..0000000
--- a/server/broker/service.go
+++ /dev/null
@@ -1,913 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package broker
-
-import (
- "context"
- "crypto/sha1"
- "encoding/json"
- "errors"
- "fmt"
- "math"
- "strconv"
- "strings"
- "time"
-
- "github.com/apache/servicecomb-service-center/datasource"
- "github.com/apache/servicecomb-service-center/datasource/etcd/client"
- serviceUtil
"github.com/apache/servicecomb-service-center/datasource/etcd/util"
- "github.com/apache/servicecomb-service-center/pkg/log"
- "github.com/apache/servicecomb-service-center/pkg/util"
- "github.com/apache/servicecomb-service-center/server/broker/brokerpb"
- apt "github.com/apache/servicecomb-service-center/server/core"
- pb "github.com/go-chassis/cari/discovery"
-)
-
-var ServiceAPI = &Service{}
-
-type Service struct {
-}
-
-func (*Service) GetBrokerHome(ctx context.Context,
- in *brokerpb.BaseBrokerRequest) (*brokerpb.BrokerHomeResponse, error) {
-
- if in == nil || len(in.HostAddress) == 0 {
- PactLogger.Errorf(nil, "Get Participant versions request
failed: invalid params.")
- return &brokerpb.BrokerHomeResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"Request format invalid."),
- }, nil
- }
-
- return GetBrokerHomeResponse(in.HostAddress, in.Scheme), nil
-}
-
-func (*Service) GetPactsOfProvider(ctx context.Context,
- in *brokerpb.GetProviderConsumerVersionPactRequest)
(*brokerpb.GetProviderConsumerVersionPactResponse, error) {
- PactLogger.Infof("GetPactsOfProvider: (%s, %s, %s)\n",
- in.ProviderId, in.ConsumerId, in.Version)
-
- resp, pactID, err := RetrieveProviderConsumerPact(ctx, in)
- if err != nil || resp.GetPact() == nil || pactID == -1 {
- var message string
- if resp != nil {
- message = resp.Response.GetMessage()
- }
- PactLogger.Errorf(err, "Get pacts of provider failed: %s\n",
message)
- return &brokerpb.GetProviderConsumerVersionPactResponse{
- Response: resp.Response,
- }, err
- }
-
- urlValue := GenerateBrokerAPIPath(in.BaseUrl.Scheme,
in.BaseUrl.HostAddress,
- PublishVerificationURL,
- strings.NewReplacer(":providerId", in.ProviderId,
- ":consumerID", in.ConsumerId,
- ":pact", strconv.FormatInt(int64(pactID), 10)))
-
- links := ",\"_links\": {" +
- "\"pb:publish-verification-results\": {" +
- "\"title\": \"Publish verification results\"," +
- "\"href\": \"" + urlValue +
- "\"" +
- "}" +
- "}}"
-
- linksBytes := []byte(links)
- pactBytes := resp.GetPact()
- sliceOfResp := pactBytes[0 : len(pactBytes)-2]
- finalBytes := append(sliceOfResp, linksBytes...)
-
- return &brokerpb.GetProviderConsumerVersionPactResponse{
- Response: pb.CreateResponse(pb.ResponseSuccess, "Success."),
- Pact: finalBytes,
- }, nil
-
-}
-
-func (*Service) DeletePacts(ctx context.Context,
- in *brokerpb.BaseBrokerRequest) (*pb.Response, error) {
-
- resp, err := DeletePactData(ctx, in)
-
- return resp, err
-}
-
-func (*Service) RetrieveProviderPacts(ctx context.Context,
- in *brokerpb.GetAllProviderPactsRequest)
(*brokerpb.GetAllProviderPactsResponse, error) {
- if in == nil || len(in.ProviderId) == 0 {
- PactLogger.Errorf(nil, "all provider pact retrieve request
failed: invalid params.")
- return &brokerpb.GetAllProviderPactsResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"Request format invalid."),
- }, nil
- }
- tenant := GetDefaultTenantProject()
-
- provider, err := serviceUtil.GetService(ctx, tenant, in.ProviderId)
- if err != nil {
- if errors.Is(err, datasource.ErrNoData) {
- PactLogger.Debug(fmt.Sprintf("all provider pact
retrieve failed, providerId is %s: provider not exist.", in.ProviderId))
- return &brokerpb.GetAllProviderPactsResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "Provider does not exist."),
- }, nil
- }
- PactLogger.Error(fmt.Sprintf("all provider pact retrieve
failed, providerId is %s: query provider failed.", in.ProviderId), err)
- return &brokerpb.GetAllProviderPactsResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams, "Query
provider failed."),
- }, err
- }
- // Get the provider participant
- //providerParticipantKey := apt.GenerateBrokerParticipantKey(tenant,
provider.AppId, provider.ServiceName)
- providerParticipant, err := GetParticipant(ctx, tenant, provider.AppId,
provider.ServiceName)
- if err != nil || providerParticipant == nil {
- PactLogger.Errorf(nil, "all provider pact retrieve failed,
provider participant cannot be searched.", in.ProviderId)
- return &brokerpb.GetAllProviderPactsResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"Provider participant cannot be searched."),
- }, err
- }
- PactLogger.Infof("[RetrieveProviderPacts] Provider participant id :
%d", providerParticipant.Id)
- // Get all versions
- versionKey := util.StringJoin([]string{GetBrokerVersionKey(tenant),
""}, "/")
- versions, err := Store().Version().Search(ctx,
- client.WithPrefix(),
- client.WithStrKey(versionKey))
-
- if err != nil {
- return nil, err
- }
- if len(versions.Kvs) == 0 {
- PactLogger.Info("[RetrieveProviderPacts] No versions found,
sorry")
- return nil, nil
- }
- // Store versions in a map
- versionObjects := make(map[int32]brokerpb.Version)
- for i := 0; i < len(versions.Kvs); i++ {
- version := &brokerpb.Version{}
- err = json.Unmarshal(versions.Kvs[i].Value.([]byte), version)
- if err != nil {
- return nil, err
- }
- PactLogger.Infof("[RetrieveProviderPacts] Version found : (%d,
%s)", version.Id, version.Number)
- versionObjects[version.Id] = *version
- }
- // Get all pactversions and filter using the provider participant id
- pactVersionKey :=
util.StringJoin([]string{GetBrokerPactVersionKey(tenant), ""}, "/")
- pactVersions, err := Store().PactVersion().Search(ctx,
- client.WithStrKey(pactVersionKey),
- client.WithPrefix())
-
- if err != nil {
- return nil, err
- }
- if len(pactVersions.Kvs) == 0 {
- PactLogger.Info("[RetrieveProviderPacts] No pact version found,
sorry")
- return nil, nil
- }
- participantToVersionObj := make(map[int32]brokerpb.Version)
- for i := 0; i < len(pactVersions.Kvs); i++ {
- pactVersion := &brokerpb.PactVersion{}
- err = json.Unmarshal(pactVersions.Kvs[i].Value.([]byte),
pactVersion)
- if err != nil {
- return nil, err
- }
- if pactVersion.ProviderParticipantId != providerParticipant.Id {
- continue
- }
- PactLogger.Infof("[RetrieveProviderPacts] Pact version found:
(%d, %d, %d, %d)", pactVersion.Id, pactVersion.VersionId, pactVersion.PactId,
pactVersion.ProviderParticipantId)
- vObj := versionObjects[pactVersion.VersionId]
- if v1Obj, ok := participantToVersionObj[vObj.ParticipantId]; ok
{
- if vObj.Order > v1Obj.Order {
- participantToVersionObj[vObj.ParticipantId] =
vObj
- }
- } else {
- participantToVersionObj[vObj.ParticipantId] = vObj
- }
- }
- // Get all participants
- participantKey :=
util.StringJoin([]string{GetBrokerParticipantKey(tenant), ""}, "/")
- participants, err := Store().Participant().Search(ctx,
- client.WithStrKey(participantKey),
- client.WithPrefix())
-
- if err != nil {
- return nil, err
- }
- if len(participants.Kvs) == 0 {
- return nil, nil
- }
- consumerInfoArr := make([]*brokerpb.ConsumerInfo, 0)
- for i := 0; i < len(participants.Kvs); i++ {
- participant := &brokerpb.Participant{}
- err = json.Unmarshal(participants.Kvs[i].Value.([]byte),
participant)
- if err != nil {
- return nil, err
- }
- if _, ok := participantToVersionObj[participant.Id]; !ok {
- continue
- }
- PactLogger.Infof("[RetrieveProviderPacts] Consumer found: (%d,
%s, %s)", participant.Id, participant.AppId, participant.ServiceName)
- consumerVersion :=
participantToVersionObj[participant.Id].Number
- consumerID, err := serviceUtil.GetServiceID(ctx,
&pb.MicroServiceKey{
- Tenant: tenant,
- AppId: participant.AppId,
- ServiceName: participant.ServiceName,
- Version: consumerVersion,
- })
- if err != nil {
- return nil, err
- }
- PactLogger.Infof("[RetrieveProviderPacts] Consumer microservice
found: %s", consumerID)
-
- urlValue := GenerateBrokerAPIPath(in.BaseUrl.Scheme,
in.BaseUrl.HostAddress,
- PublishURL,
- strings.NewReplacer(":providerId", in.ProviderId,
- ":consumerID", consumerID,
- ":number", consumerVersion))
-
- consumerInfo := &brokerpb.ConsumerInfo{
- Href: urlValue,
- Name: consumerID,
- }
- consumerInfoArr = append(consumerInfoArr, consumerInfo)
- }
- links := &brokerpb.Links{
- Pacts: consumerInfoArr,
- }
- resJSON, err := json.Marshal(links)
- if err != nil {
- return nil, err
- }
- PactLogger.Infof("Json : %s", string(resJSON))
- response := &brokerpb.GetAllProviderPactsResponse{
- Response: pb.CreateResponse(pb.ResponseSuccess, "retrieve
provider pact info succeeded."),
- XLinks: links,
- }
- return response, nil
-}
-
-func (*Service) GetAllProviderPacts(ctx context.Context,
- in *brokerpb.GetAllProviderPactsRequest)
(*brokerpb.GetAllProviderPactsResponse, error) {
-
- if in == nil || len(in.ProviderId) == 0 {
- PactLogger.Errorf(nil, "all provider pact retrieve request
failed: invalid params.")
- return &brokerpb.GetAllProviderPactsResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"Request format invalid."),
- }, nil
- }
- tenant := GetDefaultTenantProject()
-
- provider, err := serviceUtil.GetService(ctx, tenant, in.ProviderId)
- if err != nil {
- if errors.Is(err, datasource.ErrNoData) {
- PactLogger.Debug(fmt.Sprintf("all provider pact
retrieve failed, providerId is %s: provider not exist.", in.ProviderId))
- return &brokerpb.GetAllProviderPactsResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "Provider does not exist."),
- }, nil
- }
- PactLogger.Error(fmt.Sprintf("all provider pact retrieve
failed, providerId is %s: query provider failed.", in.ProviderId), err)
- return &brokerpb.GetAllProviderPactsResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams, "Query
provider failed."),
- }, err
- }
- // Get the provider participant
- //providerParticipantKey := apt.GenerateBrokerParticipantKey(tenant,
provider.AppId, provider.ServiceName)
- providerParticipant, err := GetParticipant(ctx, tenant, provider.AppId,
provider.ServiceName)
- if err != nil || providerParticipant == nil {
- PactLogger.Errorf(nil, "all provider pact retrieve failed,
provider participant cannot be searched.", in.ProviderId)
- return &brokerpb.GetAllProviderPactsResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"Provider participant cannot be searched."),
- }, err
- }
- PactLogger.Infof("[RetrieveProviderPacts] Provider participant id :
%d", providerParticipant.Id)
- // Get all versions
- versionKey := util.StringJoin([]string{GetBrokerVersionKey(tenant),
""}, "/")
- versions, err := Store().Version().Search(ctx,
- client.WithPrefix(),
- client.WithStrKey(versionKey))
-
- if err != nil {
- return nil, err
- }
- if len(versions.Kvs) == 0 {
- PactLogger.Info("[RetrieveProviderPacts] No versions found,
sorry")
- return nil, nil
- }
- // Store versions in a map
- versionObjects := make(map[int32]brokerpb.Version)
- for i := 0; i < len(versions.Kvs); i++ {
- version := &brokerpb.Version{}
- err = json.Unmarshal(versions.Kvs[i].Value.([]byte), version)
- if err != nil {
- return nil, err
- }
- PactLogger.Infof("[RetrieveProviderPacts] Version found : (%d,
%s)", version.Id, version.Number)
- versionObjects[version.Id] = *version
- }
- // Get all pactversions and filter using the provider participant id
- pactVersionKey :=
util.StringJoin([]string{GetBrokerPactVersionKey(tenant), ""}, "/")
- pactVersions, err := Store().PactVersion().Search(ctx,
- client.WithStrKey(pactVersionKey),
- client.WithPrefix())
-
- if err != nil {
- return nil, err
- }
- if len(pactVersions.Kvs) == 0 {
- PactLogger.Info("[RetrieveProviderPacts] No pact version found,
sorry")
- return nil, nil
- }
- participantToVersionObj := make(map[int32]brokerpb.Version)
- for i := 0; i < len(pactVersions.Kvs); i++ {
- pactVersion := &brokerpb.PactVersion{}
- err = json.Unmarshal(pactVersions.Kvs[i].Value.([]byte),
pactVersion)
- if err != nil {
- return nil, err
- }
- if pactVersion.ProviderParticipantId != providerParticipant.Id {
- continue
- }
- PactLogger.Infof("[RetrieveProviderPacts] Pact version found:
(%d, %d, %d, %d)", pactVersion.Id, pactVersion.VersionId, pactVersion.PactId,
pactVersion.ProviderParticipantId)
- vObj := versionObjects[pactVersion.VersionId]
- if v1Obj, ok := participantToVersionObj[vObj.ParticipantId]; ok
{
- if vObj.Order > v1Obj.Order {
- participantToVersionObj[vObj.ParticipantId] =
vObj
- }
- } else {
- participantToVersionObj[vObj.ParticipantId] = vObj
- }
- }
- // Get all participants
- participantKey :=
util.StringJoin([]string{GetBrokerParticipantKey(tenant), ""}, "/")
- participants, err := Store().Participant().Search(ctx,
- client.WithStrKey(participantKey),
- client.WithPrefix())
-
- if err != nil {
- return nil, err
- }
- if len(participants.Kvs) == 0 {
- return nil, nil
- }
- consumerInfoArr := make([]*brokerpb.ConsumerInfo, 0)
- for i := 0; i < len(participants.Kvs); i++ {
- participant := &brokerpb.Participant{}
- err = json.Unmarshal(participants.Kvs[i].Value.([]byte),
participant)
- if err != nil {
- return nil, err
- }
- if _, ok := participantToVersionObj[participant.Id]; !ok {
- continue
- }
- PactLogger.Infof("[RetrieveProviderPacts] Consumer found: (%d,
%s, %s)", participant.Id, participant.AppId, participant.ServiceName)
- consumerVersion :=
participantToVersionObj[participant.Id].Number
- consumerID, err := serviceUtil.GetServiceID(ctx,
&pb.MicroServiceKey{
- Tenant: tenant,
- AppId: participant.AppId,
- ServiceName: participant.ServiceName,
- Version: consumerVersion,
- })
- if err != nil {
- return nil, err
- }
- PactLogger.Infof("[RetrieveProviderPacts] Consumer microservice
found: %s", consumerID)
-
- urlValue := GenerateBrokerAPIPath(in.BaseUrl.Scheme,
in.BaseUrl.HostAddress,
- PublishURL,
- strings.NewReplacer(":providerId", in.ProviderId,
- ":consumerID", consumerID,
- ":number", consumerVersion))
-
- consumerInfo := &brokerpb.ConsumerInfo{
- Href: urlValue,
- Name: consumerID,
- }
- consumerInfoArr = append(consumerInfoArr, consumerInfo)
- }
- links := &brokerpb.Links{
- Pacts: consumerInfoArr,
- }
- resJSON, err := json.Marshal(links)
- if err != nil {
- return nil, err
- }
- PactLogger.Infof("Json : %s", string(resJSON))
- response := &brokerpb.GetAllProviderPactsResponse{
- Response: pb.CreateResponse(pb.ResponseSuccess, "retrieve
provider pact info succeeded."),
- XLinks: links,
- }
- return response, nil
-}
-
-func (*Service) RetrieveVerificationResults(ctx context.Context, in
*brokerpb.RetrieveVerificationRequest) (*brokerpb.RetrieveVerificationResponse,
error) {
- if in == nil || len(in.ConsumerId) == 0 || len(in.ConsumerVersion) == 0
{
- PactLogger.Errorf(nil, "verification result retrieve request
failed: invalid params.")
- return &brokerpb.RetrieveVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"Request format invalid."),
- }, nil
- }
- tenant := GetDefaultTenantProject()
- consumer, err := serviceUtil.GetService(ctx, tenant, in.ConsumerId)
- if err != nil {
- if errors.Is(err, datasource.ErrNoData) {
- PactLogger.Debug(fmt.Sprintf("verification result
retrieve request failed, consumerID is %s: consumer not exist.", in.ConsumerId))
- return &brokerpb.RetrieveVerificationResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "Consumer does not exist."),
- }, nil
- }
- PactLogger.Error(fmt.Sprintf("verification result retrieve
request failed, consumerID is %s: query consumer failed.", in.ConsumerId), err)
- return &brokerpb.RetrieveVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams, "Query
consumer failed."),
- }, err
- }
- PactLogger.Infof("Consumer service found: (%s, %s, %s, %s)",
consumer.ServiceId, consumer.AppId, consumer.ServiceName, consumer.Version)
- // Get consumer participant
- consumerParticipant, err := GetParticipant(ctx, tenant, consumer.AppId,
consumer.ServiceName)
- if err != nil || consumerParticipant == nil {
- PactLogger.Errorf(nil, "verification result retrieve request
failed, consumer participant cannot be searched.", in.ConsumerId)
- return &brokerpb.RetrieveVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"consumer participant cannot be searched."),
- }, err
- }
- PactLogger.Infof("Consumer participant found: (%d, %s, %s)",
consumerParticipant.Id, consumerParticipant.AppId,
consumerParticipant.ServiceName)
- // Get version
- version, err := GetVersion(ctx, tenant, consumer.Version,
consumerParticipant.Id)
- if err != nil || version == nil {
- PactLogger.Errorf(nil, "verification result retrieve request
failed, version cannot be searched.")
- return &brokerpb.RetrieveVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"version cannot be searched."),
- }, err
- }
- PactLogger.Infof("Version found/created: (%d, %s, %d, %d)", version.Id,
version.Number, version.ParticipantId, version.Order)
- key := util.StringJoin([]string{GetBrokerPactVersionKey(tenant),
strconv.Itoa(int(version.Id))}, "/")
- pactVersions, err := Store().PactVersion().Search(ctx,
- client.WithPrefix(),
- client.WithStrKey(key))
-
- if err != nil || len(pactVersions.Kvs) == 0 {
- PactLogger.Errorf(nil, "verification result publish request
failed, pact version cannot be searched.")
- return &brokerpb.RetrieveVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams, "pact
version cannot be searched."),
- }, err
- }
- overAllSuccess := false
-
- successfuls := make([]string, 0)
- fails := make([]string, 0)
- unknowns := make([]string, 0)
-
- verificationDetailsArr := make([]*brokerpb.VerificationDetail, 0)
- for j := 0; j < len(pactVersions.Kvs); j++ {
- pactVersion := &brokerpb.PactVersion{}
- err = json.Unmarshal(pactVersions.Kvs[j].Value.([]byte),
&pactVersion)
- if err != nil {
- PactLogger.Errorf(nil, "verification result retrieve
request failed, pact version cannot be searched.")
- return &brokerpb.RetrieveVerificationResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "pact version cannot be searched."),
- }, err
- }
- key =
util.StringJoin([]string{GetBrokerVerificationKey(tenant),
strconv.Itoa(int(pactVersion.Id))}, "/")
- verifications, err := Store().Verification().Search(ctx,
- client.WithPrefix(),
- client.WithStrKey(key))
-
- if err != nil || len(verifications.Kvs) == 0 {
- PactLogger.Errorf(nil, "verification result retrieve
request failed, verification results cannot be searched.")
- return &brokerpb.RetrieveVerificationResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "verification results cannot be
searched."),
- }, err
- }
- lastNumber := int32(math.MinInt32)
- var lastVerificationResult *brokerpb.Verification
- for i := 0; i < len(verifications.Kvs); i++ {
- verification := &brokerpb.Verification{}
- err =
json.Unmarshal(verifications.Kvs[i].Value.([]byte), &verification)
- if err != nil {
- PactLogger.Errorf(nil, "verification result
retrieve request failed, verification result unmarshall error.")
- return &brokerpb.RetrieveVerificationResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "verification result unmarshall error."),
- }, err
- }
- if verification.Number > lastNumber {
- lastNumber = verification.Number
- lastVerificationResult = verification
- }
- }
- if lastVerificationResult == nil {
- PactLogger.Errorf(nil, "verification result retrieve
request failed, verification result cannot be found.")
- return &brokerpb.RetrieveVerificationResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "verification result cannot be found."),
- }, err
- }
- PactLogger.Infof("Verification result found: (%d, %d, %d, %t,
%s, %s, %s)",
- lastVerificationResult.Id,
lastVerificationResult.Number, lastVerificationResult.PactVersionId,
- lastVerificationResult.Success,
lastVerificationResult.ProviderVersion,
- lastVerificationResult.BuildUrl,
lastVerificationResult.VerificationDate)
-
- key = util.StringJoin([]string{GetBrokerParticipantKey(tenant),
""}, "/")
- participants, err := Store().Participant().Search(ctx,
- client.WithStrKey(key),
- client.WithPrefix())
-
- if err != nil || len(participants.Kvs) == 0 {
- PactLogger.Errorf(nil, "verification result retrieve
request failed, provider participant cannot be searched.")
- return &brokerpb.RetrieveVerificationResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "provider participant cannot be
searched."),
- }, err
- }
- var providerParticipant *brokerpb.Participant
- for i := 0; i < len(participants.Kvs); i++ {
- participant := &brokerpb.Participant{}
- err =
json.Unmarshal(participants.Kvs[i].Value.([]byte), &participant)
- if err != nil {
- PactLogger.Errorf(nil, "verification result
retrieve request failed, verification result unmarshall error.")
- return &brokerpb.RetrieveVerificationResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "verification result unmarshall error."),
- }, err
- }
- if participant.Id == pactVersion.ProviderParticipantId {
- providerParticipant = participant
- break
- }
- }
- if providerParticipant == nil {
- PactLogger.Errorf(nil, "verification result retrieve
request failed, verification result unmarshall error.")
- return &brokerpb.RetrieveVerificationResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "verification result unmarshall error."),
- }, err
- }
- serviceFindReq := &pb.GetExistenceRequest{
- Type: "microservice",
- AppId: providerParticipant.AppId,
- ServiceName: providerParticipant.ServiceName,
- Version: lastVerificationResult.ProviderVersion,
- }
- resp, err := apt.ServiceAPI.Exist(ctx, serviceFindReq)
- if err != nil {
- PactLogger.Errorf(nil, "verification result retrieve
request failed, provider service cannot be found.")
- return &brokerpb.RetrieveVerificationResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "provider service cannot be found."),
- }, err
- }
- providerName := resp.ServiceId
- verificationDetail := &brokerpb.VerificationDetail{
- ProviderName: providerName,
- ProviderApplicationVersion:
lastVerificationResult.ProviderVersion,
- Success:
lastVerificationResult.Success,
- VerificationDate:
lastVerificationResult.VerificationDate,
- }
- verificationDetailsArr = append(verificationDetailsArr,
verificationDetail)
- if verificationDetail.Success {
- successfuls = append(successfuls, providerName)
- } else {
- fails = append(fails, providerName)
- }
- overAllSuccess = overAllSuccess && verificationDetail.Success
- }
- verificationDetails :=
&brokerpb.VerificationDetails{VerificationResults: verificationDetailsArr}
- verificationSummary := &brokerpb.VerificationSummary{Successful:
successfuls, Failed: fails, Unknown: unknowns}
- verificationResult := &brokerpb.VerificationResult{Success:
overAllSuccess, ProviderSummary: verificationSummary, XEmbedded:
verificationDetails}
- PactLogger.Infof("Verification result retrieved successfully ...")
- return &brokerpb.RetrieveVerificationResponse{
- Response: pb.CreateResponse(pb.ResponseSuccess, "Verification
result retrieved successfully."),
- Result: verificationResult,
- }, nil
-}
-
-func (*Service) PublishVerificationResults(ctx context.Context, in
*brokerpb.PublishVerificationRequest) (*brokerpb.PublishVerificationResponse,
error) {
- if in == nil || len(in.ProviderId) == 0 || len(in.ConsumerId) == 0 {
- PactLogger.Errorf(nil, "verification result publish request
failed: invalid params.")
- return &brokerpb.PublishVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"Request format invalid."),
- }, nil
- }
- tenant := GetDefaultTenantProject()
- consumer, err := serviceUtil.GetService(ctx, tenant, in.ConsumerId)
- if err != nil {
- if errors.Is(err, datasource.ErrNoData) {
- PactLogger.Debug(fmt.Sprintf("verification result
publish request failed, consumerID is %s: consumer not exist.", in.ConsumerId))
- return &brokerpb.PublishVerificationResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "Consumer does not exist."),
- }, nil
- }
- PactLogger.Error(fmt.Sprintf("verification result publish
request failed, consumerID is %s: query consumer failed.", in.ConsumerId), err)
- return &brokerpb.PublishVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams, "Query
consumer failed."),
- }, err
- }
- PactLogger.Info(fmt.Sprintf("consumer service found: (%s, %s, %s, %s)",
consumer.ServiceId, consumer.AppId, consumer.ServiceName, consumer.Version))
- // Get consumer participant
- consumerParticipant, err := GetParticipant(ctx, tenant, consumer.AppId,
consumer.ServiceName)
- if err != nil || consumerParticipant == nil {
- PactLogger.Errorf(nil, "verification result publish request
failed, consumer participant cannot be searched.", in.ConsumerId)
- return &brokerpb.PublishVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"consumer participant cannot be searched."),
- }, err
- }
- PactLogger.Info(fmt.Sprintf("Consumer participant found: (%d, %s, %s)",
consumerParticipant.Id, consumerParticipant.AppId,
consumerParticipant.ServiceName))
- // Get version
- version, err := GetVersion(ctx, tenant, consumer.Version,
consumerParticipant.Id)
- if err != nil || version == nil {
- PactLogger.Errorf(nil, "verification result publish request
failed, version cannot be searched.")
- return &brokerpb.PublishVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"version cannot be searched."),
- }, err
- }
- PactLogger.Infof("Version found/created: (%d, %s, %d, %d)", version.Id,
version.Number, version.ParticipantId, version.Order)
- key := util.StringJoin([]string{GetBrokerPactKey(tenant), ""}, "/")
- pacts, err := Store().Pact().Search(ctx,
- client.WithStrKey(key),
- client.WithPrefix())
-
- if err != nil || len(pacts.Kvs) == 0 {
- PactLogger.Errorf(nil, "verification result publish request
failed, pact cannot be searched.")
- return &brokerpb.PublishVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams, "pact
cannot be searched."),
- }, err
- }
- pactExists := false
- for i := 0; i < len(pacts.Kvs); i++ {
- pact := &brokerpb.Pact{}
- err = json.Unmarshal(pacts.Kvs[i].Value.([]byte), &pact)
- if err != nil {
- PactLogger.Errorf(nil, "verification result publish
request failed, pact cannot be searched.")
- return &brokerpb.PublishVerificationResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "pact cannot be searched."),
- }, err
- }
- if pact.Id == in.PactId {
- pactExists = true
- }
- }
- if !pactExists {
- PactLogger.Errorf(nil, "verification result publish request
failed, pact does not exists.")
- return &brokerpb.PublishVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams, "pact
does not exists."),
- }, err
- }
- pactVersion, err := GetPactVersion(ctx, tenant, version.Id, in.PactId)
- if err != nil || pactVersion == nil {
- PactLogger.Errorf(nil, "verification result publish request
failed, pact version cannot be searched.")
- return &brokerpb.PublishVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams, "pact
version cannot be searched."),
- }, err
- }
- // Check if some verification results already exists
- key = util.StringJoin([]string{GetBrokerVerificationKey(tenant),
strconv.Itoa(int(pactVersion.Id))}, "/")
- verifications, err := Store().Verification().Search(ctx,
- client.WithStrKey(key),
- client.WithPrefix())
-
- if err != nil {
- PactLogger.Errorf(nil, "verification result publish request
failed, verification result cannot be searched.")
- return &brokerpb.PublishVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"verification result cannot be searched."),
- }, err
- }
- lastNumber := int32(math.MinInt32)
- if len(verifications.Kvs) != 0 {
- for i := 0; i < len(verifications.Kvs); i++ {
- verification := &brokerpb.Verification{}
- err =
json.Unmarshal(verifications.Kvs[i].Value.([]byte), &verification)
- if err != nil {
- PactLogger.Errorf(nil, "verification result
publish request failed, verification result unmarshall error.")
- return &brokerpb.PublishVerificationResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "verification result unmarshall error."),
- }, err
- }
- if verification.Number > lastNumber {
- lastNumber = verification.Number
- }
- }
- }
- if lastNumber < 0 {
- lastNumber = 0
- } else {
- lastNumber++
- }
- verificationDate := time.Now().Format(time.RFC3339)
- verificationKey := GenerateBrokerVerificationKey(tenant,
pactVersion.Id, lastNumber)
- id, err := GetData(ctx, GetBrokerLatestVerificationIDKey())
- if err != nil {
- return &brokerpb.PublishVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "get data
error."),
- }, err
- }
- verification := &brokerpb.Verification{
- Id: int32(id) + 1,
- Number: lastNumber,
- PactVersionId: pactVersion.Id,
- Success: in.Success,
- ProviderVersion: in.ProviderApplicationVersion,
- BuildUrl: "",
- VerificationDate: verificationDate,
- }
- response, err := CreateVerification(ctx, verificationKey, *verification)
- if err != nil {
- return response, err
- }
- PactLogger.Infof("Verification result inserted: (%d, %d, %d, %t, %s,
%s, %s)",
- verification.Id, verification.Number,
verification.PactVersionId,
- verification.Success, verification.ProviderVersion,
verification.BuildUrl, verification.VerificationDate)
- verificationResponse := &brokerpb.VerificationDetail{
- ProviderName: in.ProviderId,
- ProviderApplicationVersion: verification.ProviderVersion,
- Success: verification.Success,
- VerificationDate: verification.VerificationDate,
- }
- PactLogger.Infof("Verification result published successfully ...")
- return &brokerpb.PublishVerificationResponse{
- Response: pb.CreateResponse(pb.ResponseSuccess,
"Verification result published successfully."),
- Confirmation: verificationResponse,
- }, nil
-}
-
-func (*Service) PublishPact(ctx context.Context, in
*brokerpb.PublishPactRequest) (*brokerpb.PublishPactResponse, error) {
- if InvalidInput(in) {
- PactLogger.Errorf(nil, "pact publish request failed: invalid
params.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"Request format invalid."),
- }, nil
- }
- tenant := GetDefaultTenantProject()
-
- provider, err := serviceUtil.GetService(ctx, tenant, in.ProviderId)
- if err != nil {
- if errors.Is(err, datasource.ErrNoData) {
- PactLogger.Debug(fmt.Sprintf("pact publish failed,
providerId is %s: provider not exist.", in.ProviderId))
- return &brokerpb.PublishPactResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "Provider does not exist."),
- }, nil
- }
- PactLogger.Error(fmt.Sprintf("pact publish failed, providerId
is %s: query provider failed.", in.ProviderId), err)
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams, "Query
provider failed."),
- }, err
- }
- PactLogger.Info(fmt.Sprintf("provider service found: (%s, %s, %s, %s)",
provider.ServiceId, provider.AppId, provider.ServiceName, provider.Version))
- consumer, err := serviceUtil.GetService(ctx, tenant, in.ConsumerId)
- if err != nil {
- if errors.Is(err, datasource.ErrNoData) {
- PactLogger.Debug(fmt.Sprintf("pact publish failed,
consumerID is %s: consumer not exist.", in.ConsumerId))
- return &brokerpb.PublishPactResponse{
- Response:
pb.CreateResponse(pb.ErrInvalidParams, "Consumer does not exist."),
- }, nil
- }
- PactLogger.Error(fmt.Sprintf("pact publish failed, consumerID
is %s: query consumer failed.", in.ConsumerId), err)
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams, "Query
consumer failed."),
- }, err
- }
-
- // check that the consumer has that vesion in the url
- if strings.Compare(consumer.Version, in.Version) != 0 {
- log.Error(fmt.Sprintf("pact publish failed, version (%s) does
not exist for consmer", in.Version), nil)
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"Consumer Version does not exist."),
- }, nil
- }
-
- PactLogger.Info(fmt.Sprintf("consumer service found: (%s, %s, %s, %s)",
consumer.ServiceId, consumer.AppId, consumer.ServiceName, consumer.Version))
- // Get or create provider participant
- providerParticipantKey := GenerateBrokerParticipantKey(tenant,
provider.AppId, provider.ServiceName)
- providerParticipant, err := GetParticipant(ctx, tenant, provider.AppId,
provider.ServiceName)
- if err != nil {
- PactLogger.Error(fmt.Sprintf("pact publish failed, provider[%s]
participant cannot be searched.", in.ProviderId), nil)
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"Provider participant cannot be searched."),
- }, err
- }
- if providerParticipant == nil {
- id, err := GetData(ctx, GetBrokerLatestParticipantIDKey())
- if err != nil {
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal,
"get data error."),
- }, err
- }
- providerParticipant = &brokerpb.Participant{Id: int32(id) + 1,
AppId: provider.AppId, ServiceName: provider.ServiceName}
- response, err := CreateParticipant(ctx, providerParticipantKey,
*providerParticipant)
- if err != nil {
- return response, err
- }
- }
- PactLogger.Infof("Provider participant found: (%d, %s, %s)",
providerParticipant.Id, providerParticipant.AppId,
providerParticipant.ServiceName)
- // Get or create consumer participant
- consumerParticipantKey := GenerateBrokerParticipantKey(tenant,
consumer.AppId, consumer.ServiceName)
- consumerParticipant, err := GetParticipant(ctx, tenant, consumer.AppId,
consumer.ServiceName)
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, consumer
participant cannot be searched.", in.ConsumerId)
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"consumer participant cannot be searched."),
- }, err
- }
- if consumerParticipant == nil {
- id, err := GetData(ctx, GetBrokerLatestParticipantIDKey())
- if err != nil {
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal,
"get data error."),
- }, err
- }
- consumerParticipant = &brokerpb.Participant{Id: int32(id) + 1,
AppId: consumer.AppId, ServiceName: consumer.ServiceName}
- response, err := CreateParticipant(ctx, consumerParticipantKey,
*consumerParticipant)
- if err != nil {
- return response, err
- }
- }
- PactLogger.Infof("Consumer participant found: (%d, %s, %s)",
consumerParticipant.Id, consumerParticipant.AppId,
consumerParticipant.ServiceName)
- // Get or create version
- versionKey := GenerateBrokerVersionKey(tenant, in.Version,
consumerParticipant.Id)
- version, err := GetVersion(ctx, tenant, in.Version,
consumerParticipant.Id)
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, version cannot be
searched.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams,
"version cannot be searched."),
- }, err
- }
- if version == nil {
- order := GetLastestVersionNumberForParticipant(ctx, tenant,
consumerParticipant.Id)
- PactLogger.Infof("Old version order: %d", order)
- order++
- id, err := GetData(ctx, GetBrokerLatestVersionIDKey())
- if err != nil {
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal,
"get data error."),
- }, err
- }
- version = &brokerpb.Version{Id: int32(id) + 1, Number:
in.Version, ParticipantId: consumerParticipant.Id, Order: order}
- response, err := CreateVersion(ctx, versionKey, *version)
- if err != nil {
- return response, err
- }
- }
- PactLogger.Infof("Version found/created: (%d, %s, %d, %d)", version.Id,
version.Number, version.ParticipantId, version.Order)
- // Get or create pact
- sha1 := sha1.Sum(in.Pact)
- var sha []byte = sha1[:]
- pactKey := GenerateBrokerPactKey(tenant, consumerParticipant.Id,
providerParticipant.Id, sha)
- pact, err := GetPact(ctx, tenant, consumerParticipant.Id,
providerParticipant.Id, sha)
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, pact cannot be
searched.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams, "pact
cannot be searched."),
- }, err
- }
- if pact == nil {
- id, err := GetData(ctx, GetBrokerLatestPactIDKey())
- if err != nil {
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal,
"get data error."),
- }, err
- }
- pact = &brokerpb.Pact{Id: int32(id) + 1, ConsumerParticipantId:
consumerParticipant.Id,
- ProviderParticipantId: providerParticipant.Id, Sha:
sha, Content: in.Pact}
- response, err := CreatePact(ctx, pactKey, *pact)
- if err != nil {
- return response, err
- }
- }
- PactLogger.Infof("Pact found/created: (%d, %d, %d, %s)", pact.Id,
pact.ConsumerParticipantId, pact.ProviderParticipantId, pact.Sha)
- // Get or create pact version
- pactVersionKey := GenerateBrokerPactVersionKey(tenant, version.Id,
pact.Id)
- pactVersion, err := GetPactVersion(ctx, tenant, version.Id, pact.Id)
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, pact version
cannot be searched.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInvalidParams, "pact
version cannot be searched."),
- }, err
- }
- if pactVersion == nil {
- id, err := GetData(ctx, GetBrokerLatestPactVersionIDKey())
- if err != nil {
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal,
"get data error."),
- }, err
- }
- pactVersion = &brokerpb.PactVersion{Id: int32(id) + 1,
VersionId: version.Id, PactId: pact.Id, ProviderParticipantId:
providerParticipant.Id}
- response, err := CreatePactVersion(ctx, pactVersionKey,
*pactVersion)
- if err != nil {
- return response, err
- }
- }
- PactLogger.Infof("PactVersion found/create: (%d, %d, %d, %d)",
pactVersion.Id, pactVersion.VersionId, pactVersion.PactId,
pactVersion.ProviderParticipantId)
- PactLogger.Infof("Pact published successfully ...")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ResponseSuccess, "Pact published
successfully."),
- }, nil
-}
-
-func InvalidInput(in *brokerpb.PublishPactRequest) bool {
- return in == nil || len(in.ProviderId) == 0 || len(in.ConsumerId) == 0
|| len(in.Version) == 0 || len(in.Pact) == 0
-}
diff --git a/server/broker/service_test.go b/server/broker/service_test.go
deleted file mode 100644
index ad255ad..0000000
--- a/server/broker/service_test.go
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package broker_test
-
-import (
- "context"
- "fmt"
-
- "github.com/apache/servicecomb-service-center/pkg/util"
- "github.com/apache/servicecomb-service-center/server/broker"
- "github.com/apache/servicecomb-service-center/server/broker/brokerpb"
- "github.com/apache/servicecomb-service-center/server/core"
- pb "github.com/go-chassis/cari/discovery"
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
-)
-
-const (
- TEST_BROKER_NO_SERVICE_ID = "noServiceId"
- TEST_BROKER_NO_VERSION = "noVersion"
- //Consumer
- TEST_BROKER_CONSUMER_VERSION = "4.0.0"
- TEST_BROKER_CONSUMER_NAME = "broker_name_consumer"
- TEST_BROKER_CONSUMER_APP = "broker_group_consumer"
- //Provider
- TEST_BROKER_PROVIDER_VERSION = "3.0.0"
- TEST_BROKER_PROVIDER_NAME = "broker_name_provider"
- TEST_BROKER_PROVIDER_APP = "broker_group_provider"
-)
-
-var consumerServiceId string
-var providerServiceId string
-
-var _ = Describe("Controller", func() {
- Describe("brokerDependency", func() {
- Context("normal", func() {
- It("PublishPact", func() {
- fmt.Println("UT===========PublishPact")
-
- //(1) create consumer service
- resp, err :=
core.ServiceAPI.Create(getContext(), &pb.CreateServiceRequest{
- Service: &pb.MicroService{
- ServiceName:
TEST_BROKER_CONSUMER_NAME,
- AppId:
TEST_BROKER_CONSUMER_APP,
- Version:
TEST_BROKER_CONSUMER_VERSION,
- Level: "FRONT",
- Schemas: []string{
- "xxxxxxxx",
- },
- Status: "UP",
- },
- })
-
- Expect(err).To(BeNil())
- consumerServiceId = resp.ServiceId
-
Expect(resp.Response.GetCode()).To(Equal(pb.ResponseSuccess))
-
- //(2) create provider service
- resp, err =
core.ServiceAPI.Create(getContext(), &pb.CreateServiceRequest{
- Service: &pb.MicroService{
- ServiceName:
TEST_BROKER_PROVIDER_NAME,
- AppId:
TEST_BROKER_PROVIDER_APP,
- Version:
TEST_BROKER_PROVIDER_VERSION,
- Level: "FRONT",
- Schemas: []string{
- "xxxxxxxx",
- },
- Status: "UP",
- Properties:
map[string]string{"allowCrossApp": "true"},
- },
- })
- Expect(err).To(BeNil())
- providerServiceId = resp.ServiceId
-
Expect(resp.Response.GetCode()).To(Equal(pb.ResponseSuccess))
-
- //(3) publish a pact between two services
- respPublishPact, err :=
brokerResource.PublishPact(getContext(),
- &brokerpb.PublishPactRequest{
- ProviderId: providerServiceId,
- ConsumerId: consumerServiceId,
- Version:
TEST_BROKER_CONSUMER_VERSION,
- Pact: []byte("hello"),
- })
-
- Expect(err).To(BeNil())
-
Expect(respPublishPact.Response.GetCode()).To(Equal(pb.ResponseSuccess))
- })
-
- It("PublishPact-noProviderServiceId", func() {
- fmt.Println("UT===========PublishPact, no
provider serviceID")
-
- //publish a pact between two services
- respPublishPact, _ :=
brokerResource.PublishPact(getContext(), &brokerpb.PublishPactRequest{
- ProviderId: TEST_BROKER_NO_SERVICE_ID,
- ConsumerId: consumerServiceId,
- Version:
TEST_BROKER_CONSUMER_VERSION,
- Pact: []byte("hello"),
- })
-
-
Expect(respPublishPact.Response.GetCode()).ToNot(Equal(pb.ResponseSuccess))
- })
-
- It("PublishPact-noConumerServiceId", func() {
- fmt.Println("UT===========PublishPact, no
consumer serviceID")
-
- //publish a pact between two services
- respPublishPact, _ :=
brokerResource.PublishPact(getContext(), &brokerpb.PublishPactRequest{
- ProviderId: providerServiceId,
- ConsumerId: TEST_BROKER_NO_SERVICE_ID,
- Version:
TEST_BROKER_CONSUMER_VERSION,
- Pact: []byte("hello"),
- })
-
-
Expect(respPublishPact.Response.GetCode()).ToNot(Equal(pb.ResponseSuccess))
- })
-
- It("PublishPact-noConumerVersion", func() {
- fmt.Println("UT===========PublishPact, no
consumer Version")
-
- //publish a pact between two services
- respPublishPact, _ :=
brokerResource.PublishPact(getContext(), &brokerpb.PublishPactRequest{
- ProviderId: providerServiceId,
- ConsumerId: consumerServiceId,
- Version: TEST_BROKER_NO_VERSION,
- Pact: []byte("hello"),
- })
-
-
Expect(respPublishPact.Response.GetCode()).ToNot(Equal(pb.ResponseSuccess))
- })
-
- It("GetBrokerHome", func() {
- fmt.Println("UT===========GetBrokerHome")
-
- respGetHome, _ :=
brokerResource.GetBrokerHome(getContext(), &brokerpb.BaseBrokerRequest{
- HostAddress: "localhost",
- Scheme: "http",
- })
-
- Expect(respGetHome).NotTo(BeNil())
-
- })
-
- It("GetBrokerAllProviderPacts", func() {
-
fmt.Println("UT===========GetBrokerAllProviderPacts")
-
- respGetAllProviderPacts, _ :=
brokerResource.GetAllProviderPacts(getContext(),
- &brokerpb.GetAllProviderPactsRequest{
- ProviderId: providerServiceId,
- BaseUrl:
&brokerpb.BaseBrokerRequest{
- HostAddress:
"localhost",
- Scheme: "http",
- }})
-
- Expect(respGetAllProviderPacts).NotTo(BeNil())
-
Expect(respGetAllProviderPacts.Response.GetCode()).To(Equal(pb.ResponseSuccess))
- })
-
- It("GetBrokerPactsOfProvider", func() {
-
fmt.Println("UT===========GetBrokerPactsOfProvider")
-
- respGetAllProviderPacts, _ :=
brokerResource.GetPactsOfProvider(getContext(),
-
&brokerpb.GetProviderConsumerVersionPactRequest{
- ProviderId: providerServiceId,
- ConsumerId: consumerServiceId,
- Version:
TEST_BROKER_CONSUMER_VERSION,
- BaseUrl:
&brokerpb.BaseBrokerRequest{
- HostAddress:
"localhost",
- Scheme: "http",
- }})
-
- Expect(respGetAllProviderPacts).NotTo(BeNil())
-
Expect(respGetAllProviderPacts.Response.GetCode()).To(Equal(pb.ResponseSuccess))
- })
-
- It("PublishVerificationResults", func() {
-
fmt.Println("UT===========PublishVerificationResults")
-
- id, err := broker.GetData(context.Background(),
broker.GetBrokerLatestPactIDKey())
- Expect(err).To(BeNil())
- respResults, err :=
brokerResource.PublishVerificationResults(getContext(),
- &brokerpb.PublishVerificationRequest{
- ProviderId:
providerServiceId,
- ConsumerId:
consumerServiceId,
- PactId:
int32(id),
- ProviderApplicationVersion:
TEST_BROKER_PROVIDER_VERSION,
- })
-
- Expect(respResults).NotTo(BeNil())
-
Expect(respResults.Response.GetCode()).To(Equal(pb.ResponseSuccess))
- })
-
- It("RetrieveVerificationResults", func() {
-
fmt.Println("UT===========RetrieveVerificationResults")
-
- respVerification, _ :=
brokerResource.RetrieveVerificationResults(getContext(),
- &brokerpb.RetrieveVerificationRequest{
- ConsumerId:
consumerServiceId,
- ConsumerVersion:
TEST_BROKER_CONSUMER_VERSION,
- })
-
- Expect(respVerification).NotTo(BeNil())
-
Expect(respVerification.Response.GetCode()).To(Equal(pb.ResponseSuccess))
- })
-
- It("RetrieveProviderPacts", func() {
-
fmt.Println("UT===========RetrieveProviderPacts")
-
- respProviderPact, _ :=
brokerResource.RetrieveProviderPacts(getContext(),
- &brokerpb.GetAllProviderPactsRequest{
- ProviderId: providerServiceId,
- BaseUrl:
&brokerpb.BaseBrokerRequest{
- HostAddress:
"localhost",
- Scheme: "http",
- },
- })
-
- Expect(respProviderPact).NotTo(BeNil())
-
Expect(respProviderPact.Response.GetCode()).To(Equal(pb.ResponseSuccess))
- })
- })
- })
-})
-
-func getContext() context.Context {
- ctx := context.TODO()
- ctx = util.SetDomain(ctx, "default")
- ctx = util.SetProject(ctx, "default")
- ctx = util.WithNoCache(ctx)
- return ctx
-}
diff --git a/server/broker/store.go b/server/broker/store.go
deleted file mode 100644
index a5f2810..0000000
--- a/server/broker/store.go
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package broker
-
-import (
- "github.com/apache/servicecomb-service-center/datasource/etcd/kv"
- "github.com/apache/servicecomb-service-center/datasource/etcd/sd"
-)
-
-var (
- PARTICIPANT sd.Type
- VERSION sd.Type
- PACT sd.Type
- PactVersion sd.Type
- PactTag sd.Type
- VERIFICATION sd.Type
- PactLatest sd.Type
-)
-
-var brokerKvStore = &BKvStore{}
-
-type BKvStore struct {
-}
-
-func (s *BKvStore) Participant() sd.Indexer {
- return kv.Store().Adaptors(PARTICIPANT)
-}
-
-func (s *BKvStore) Version() sd.Indexer {
- return kv.Store().Adaptors(VERSION)
-}
-
-func (s *BKvStore) Pact() sd.Indexer {
- return kv.Store().Adaptors(PACT)
-}
-
-func (s *BKvStore) PactVersion() sd.Indexer {
- return kv.Store().Adaptors(PactVersion)
-}
-
-func (s *BKvStore) PactTag() sd.Indexer {
- return kv.Store().Adaptors(PactTag)
-}
-
-func (s *BKvStore) Verification() sd.Indexer {
- return kv.Store().Adaptors(VERIFICATION)
-}
-
-func (s *BKvStore) PactLatest() sd.Indexer {
- return kv.Store().Adaptors(PactLatest)
-}
-
-func Store() *BKvStore {
- return brokerKvStore
-}
diff --git a/server/broker/util.go b/server/broker/util.go
deleted file mode 100644
index 66bec20..0000000
--- a/server/broker/util.go
+++ /dev/null
@@ -1,578 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package broker
-
-import (
- "context"
- "encoding/json"
- "errors"
- "fmt"
- "math"
- "net/url"
- "strconv"
- "strings"
-
- "github.com/apache/servicecomb-service-center/datasource"
- "github.com/apache/servicecomb-service-center/datasource/etcd/client"
- serviceUtil
"github.com/apache/servicecomb-service-center/datasource/etcd/util"
- "github.com/apache/servicecomb-service-center/pkg/log"
- "github.com/apache/servicecomb-service-center/pkg/util"
- "github.com/apache/servicecomb-service-center/server/broker/brokerpb"
- pb "github.com/go-chassis/cari/discovery"
-)
-
-var PactLogger *log.Logger
-
-const (
- HomeURL = "/"
- ParticipantsURL = "/participants"
- ProviderLatestPactsURL = "/pacts/provider/:providerId/latest"
- ProviderLatestPactsTagURL = "/pacts/provider/:providerId/latest/:tag"
- PactsLatestURL = "/pacts/latest"
-
- PublishURL =
"/pacts/provider/:providerId/consumer/:consumerId/version/:number"
- PublishVerificationURL =
"/pacts/provider/:providerId/consumer/:consumerId/pact-version/:pact/verification-results"
- WebhooksURL = "/webhooks"
-
- CuriesURL = "/doc/:rel"
-)
-
-var brokerAPILinksValues = map[string]string{
- "self": HomeURL,
- "pb:publish-pact": PublishURL,
- "pb:latest-pact-versions": PactsLatestURL,
- "pb:pacticipants": ParticipantsURL,
- "pb:latest-provider-pacts": ProviderLatestPactsURL,
- "pb:latest-provider-pacts-with-tag": ProviderLatestPactsTagURL,
- "pb:webhooks": WebhooksURL,
-}
-
-var brokerAPILinksTempl = map[string]bool{
- "self": false,
- "pb:publish-pact": true,
- "pb:latest-pact-versions": false,
- "pb:pacticipants": false,
- "pb:latest-provider-pacts": true,
- "pb:latest-provider-pacts-with-tag": true,
- "pb:webhooks": false,
-}
-
-var brokerAPILinksTitles = map[string]string{
- "self": "Index",
- "pb:publish-pact": "Publish a pact",
- "pb:latest-pact-versions": "Latest pact versions",
- "pb:pacticipants": "Pacticipants",
- "pb:latest-provider-pacts": "Latest pacts by provider",
- "pb:latest-provider-pacts-with-tag": "Latest pacts by provider with a
specified tag",
- "pb:webhooks": "Webhooks",
-}
-
-func GetDefaultTenantProject() string {
- return util.StringJoin([]string{"default", "default"}, "/")
-}
-
-//GenerateBrokerAPIPath creates the API link from the constant template
-func GenerateBrokerAPIPath(scheme string, host string, apiPath string,
- replacer *strings.Replacer) string {
- genPath := url.URL{
- Scheme: scheme,
- Host: host,
- Path: apiPath,
- }
- if replacer != nil {
- return replacer.Replace(genPath.String())
- }
- return genPath.String()
-}
-
-//GetBrokerHomeLinksAPIS return the generated Home links
-func GetBrokerHomeLinksAPIS(scheme string, host string, apiKey string) string {
- return GenerateBrokerAPIPath(scheme, host, brokerAPILinksValues[apiKey],
- strings.NewReplacer(":providerId", "{provider}",
- ":consumerId", "{consumer}",
- ":number", "{consumerApplicationVersion}",
- ":tag", "{tag}"))
-}
-
-//CreateBrokerHomeResponse create the templated broker home response
-func CreateBrokerHomeResponse(host string, scheme string)
*brokerpb.BrokerHomeResponse {
- apiEntries := make(map[string]*brokerpb.BrokerAPIInfoEntry)
-
- for k := range brokerAPILinksValues {
- apiEntries[k] = &brokerpb.BrokerAPIInfoEntry{
- Href: GetBrokerHomeLinksAPIS(scheme, host, k),
- Title: brokerAPILinksTitles[k],
- Templated: brokerAPILinksTempl[k],
- }
- }
-
- curies := []*brokerpb.BrokerAPIInfoEntry{}
- curies = append(curies, &brokerpb.BrokerAPIInfoEntry{
- Name: "pb",
- Href: GenerateBrokerAPIPath(scheme, host, CuriesURL,
- strings.NewReplacer(":rel", "{rel}")),
- })
-
- return &brokerpb.BrokerHomeResponse{
- Response: pb.CreateResponse(pb.ResponseSuccess, "Broker Home."),
- XLinks: apiEntries,
- Curies: curies,
- }
-}
-
-//GetBrokerHomeResponse gets the homeResponse from cache if it exists
-func GetBrokerHomeResponse(host string, scheme string)
*brokerpb.BrokerHomeResponse {
- brokerResp := CreateBrokerHomeResponse(host, scheme)
- if brokerResp == nil {
- return nil
- }
- return brokerResp
-}
-
-func GetParticipant(ctx context.Context, domain string, appID string,
- serviceName string) (*brokerpb.Participant, error) {
- key := GenerateBrokerParticipantKey(domain, appID, serviceName)
- participants, err := Store().Participant().Search(ctx,
client.WithStrKey(key))
- if err != nil {
- return nil, err
- }
- if len(participants.Kvs) == 0 {
- PactLogger.Info("GetParticipant found no participant")
- return nil, nil
- }
- participant := &brokerpb.Participant{}
- err = json.Unmarshal(participants.Kvs[0].Value.([]byte), participant)
- if err != nil {
- return nil, err
- }
- PactLogger.Infof("GetParticipant: (%d, %s, %s)", participant.Id,
participant.AppId, participant.ServiceName)
- return participant, nil
-}
-
-func GetVersion(ctx context.Context, domain string, number string,
- participantID int32) (*brokerpb.Version, error) {
- key := GenerateBrokerVersionKey(domain, number, participantID)
- versions, err := Store().Version().Search(ctx, client.WithStrKey(key))
- if err != nil {
- return nil, err
- }
- if len(versions.Kvs) == 0 {
- return nil, nil
- }
- version := &brokerpb.Version{}
- err = json.Unmarshal(versions.Kvs[0].Value.([]byte), version)
- if err != nil {
- return nil, err
- }
- PactLogger.Infof("GetVersion: (%d, %s, %d, %d)", version.Id,
version.Number, version.ParticipantId, version.Order)
- return version, nil
-}
-
-func GetPact(ctx context.Context, domain string, consumerParticipantID int32,
producerParticipantID int32, sha []byte) (*brokerpb.Pact, error) {
- key := GenerateBrokerPactKey(domain, consumerParticipantID,
producerParticipantID, sha)
- versions, err := Store().Pact().Search(ctx, client.WithStrKey(key))
- if err != nil {
- return nil, err
- }
- if len(versions.Kvs) == 0 {
- return nil, nil
- }
- pact := &brokerpb.Pact{}
- err = json.Unmarshal(versions.Kvs[0].Value.([]byte), pact)
- if err != nil {
- return nil, err
- }
- PactLogger.Infof("GetPact: (%d, %d, %d, %s, %s)", pact.Id,
pact.ConsumerParticipantId, pact.ProviderParticipantId, string(pact.Sha),
string(pact.Content))
- return pact, nil
-}
-
-func GetPactVersion(ctx context.Context, domain string, versionID int32,
- pactID int32) (*brokerpb.PactVersion, error) {
- key := GenerateBrokerPactVersionKey(domain, versionID, pactID)
- versions, err := Store().PactVersion().Search(ctx,
client.WithStrKey(key))
- if err != nil {
- return nil, err
- }
- if len(versions.Kvs) == 0 {
- return nil, nil
- }
- pactVersion := &brokerpb.PactVersion{}
- err = json.Unmarshal(versions.Kvs[0].Value.([]byte), pactVersion)
- if err != nil {
- return nil, err
- }
- PactLogger.Infof("GetPactVersion: (%d, %d, %d, %d)", pactVersion.Id,
pactVersion.VersionId, pactVersion.PactId, pactVersion.ProviderParticipantId)
- return pactVersion, nil
-}
-
-func GetData(ctx context.Context, key string) (int, error) {
- values, err := Store().PactLatest().Search(ctx, client.WithStrKey(key))
- if err != nil {
- return -1, err
- }
- if len(values.Kvs) == 0 {
- return -1, nil
- }
- id, err := strconv.Atoi(string(values.Kvs[0].Value.([]byte)))
- if err != nil {
- return -1, err
- }
- return id, nil
-}
-
-func CreateParticipant(ctx context.Context, participantKey string, participant
brokerpb.Participant) (*brokerpb.PublishPactResponse, error) {
- data, err := json.Marshal(participant)
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, participant cannot
be created.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal,
"participant cannot be created."),
- }, err
- }
-
- _, err = client.Instance().Do(ctx, client.PUT,
- client.WithStrKey(participantKey),
- client.WithValue(data))
-
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, participant cannot
be created.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal,
"participant cannot be created."),
- }, err
- }
-
- k := GetBrokerLatestParticipantIDKey()
- v := strconv.Itoa(int(participant.Id))
- PactLogger.Infof("Inserting (%s, %s)", k, v)
- err = client.Put(ctx, k, v)
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, participant cannot
be created.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal,
"participant cannot be created."),
- }, err
- }
- PactLogger.Infof("Participant created for key: %s", participantKey)
- return nil, nil
-}
-
-func CreateVersion(ctx context.Context, versionKey string,
- version brokerpb.Version) (*brokerpb.PublishPactResponse, error) {
- data, err := json.Marshal(version)
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, version cannot be
created.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "version
cannot be created."),
- }, err
- }
-
- _, err = client.Instance().Do(ctx, client.PUT,
- client.WithStrKey(versionKey),
- client.WithValue(data))
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, version cannot be
created.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "version
cannot be created."),
- }, err
- }
- k := GetBrokerLatestVersionIDKey()
- v := strconv.Itoa(int(version.Id))
- PactLogger.Infof("Inserting (%s, %s)", k, v)
- err = client.Put(ctx, k, v)
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, version cannot be
created.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "version
cannot be created."),
- }, err
- }
- PactLogger.Infof("Version created for key: %s", versionKey)
- return nil, nil
-}
-
-func CreatePact(ctx context.Context,
- pactKey string, pact brokerpb.Pact) (*brokerpb.PublishPactResponse,
error) {
- data, err := json.Marshal(pact)
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, pact cannot be
created.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "pact
cannot be created."),
- }, err
- }
-
- _, err = client.Instance().Do(ctx,
- client.PUT,
- client.WithStrKey(pactKey),
- client.WithValue(data))
-
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, pact cannot be
created.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "pact
cannot be created."),
- }, err
- }
- k := GetBrokerLatestPactIDKey()
- v := strconv.Itoa(int(pact.Id))
- PactLogger.Infof("Inserting (%s, %s)", k, v)
- err = client.Put(ctx, k, v)
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, pact cannot be
created.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "pact
cannot be created."),
- }, err
- }
- PactLogger.Infof("Pact created for key: %s", pactKey)
- return nil, nil
-}
-
-func CreatePactVersion(ctx context.Context, pactVersionKey string, pactVersion
brokerpb.PactVersion) (*brokerpb.PublishPactResponse, error) {
- data, err := json.Marshal(pactVersion)
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, pact version
cannot be created.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "pact
version cannot be created."),
- }, err
- }
-
- _, err = client.Instance().Do(ctx,
- client.PUT, client.WithValue(data),
client.WithStrKey(pactVersionKey))
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, pact version
cannot be created.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "pact
version cannot be created."),
- }, err
- }
- k := GetBrokerLatestPactVersionIDKey()
- v := strconv.Itoa(int(pactVersion.Id))
- PactLogger.Infof("Inserting (%s, %s)", k, v)
- err = client.Put(ctx, k, v)
- if err != nil {
- PactLogger.Errorf(nil, "pact publish failed, pact version
cannot be created.")
- return &brokerpb.PublishPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "pact
version cannot be created."),
- }, err
- }
- PactLogger.Infof("Pact version created for key: %s", pactVersionKey)
- return nil, nil
-}
-
-func CreateVerification(ctx context.Context,
- verificationKey string, verification brokerpb.Verification)
(*brokerpb.PublishVerificationResponse, error) {
- data, err := json.Marshal(verification)
- if err != nil {
- PactLogger.Errorf(nil, "verification result publish failed,
verification result marshal error.")
- return &brokerpb.PublishVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInternal,
"verification result marshal error."),
- }, err
- }
-
- _, err = client.Instance().Do(ctx, client.PUT,
- client.WithStrKey(verificationKey),
- client.WithValue(data))
- if err != nil {
- PactLogger.Errorf(nil, "verification result publish failed,
verification result cannot be created.")
- return &brokerpb.PublishVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInternal,
"verification result cannot be created."),
- }, err
- }
- k := GetBrokerLatestVerificationIDKey()
- v := strconv.Itoa(int(verification.Id))
- PactLogger.Infof("Inserting (%s, %s)", k, v)
- err = client.Put(ctx, k, v)
- if err != nil {
- PactLogger.Errorf(nil, "verification result publish failed,
verification result cannot be created.")
- return &brokerpb.PublishVerificationResponse{
- Response: pb.CreateResponse(pb.ErrInternal,
"verification result cannot be created."),
- }, err
- }
- PactLogger.Infof("Verification result created for key: %s",
verificationKey)
- return nil, nil
-}
-
-func GetLastestVersionNumberForParticipant(ctx context.Context,
- tenant string, participantID int32) int32 {
- key := util.StringJoin([]string{
- GetBrokerVersionKey(tenant), ""}, "/")
- versions, err := Store().Version().Search(ctx,
- client.WithStrKey(key),
- client.WithPrefix())
-
- if err != nil || len(versions.Kvs) == 0 {
- return -1
- }
- order := int32(math.MinInt32)
- for i := 0; i < len(versions.Kvs); i++ {
- version := &brokerpb.Version{}
- err = json.Unmarshal(versions.Kvs[i].Value.([]byte), &version)
- if err != nil {
- return -1
- }
- if version.ParticipantId != participantID {
- continue
- }
- if version.Order > order {
- order = version.Order
- }
- }
- return order
-}
-
-func RetrieveProviderConsumerPact(ctx context.Context,
- in *brokerpb.GetProviderConsumerVersionPactRequest)
(*brokerpb.GetProviderConsumerVersionPactResponse, int32, error) {
- if in == nil || len(in.ProviderId) == 0 || len(in.ConsumerId) == 0 ||
len(in.Version) == 0 {
- PactLogger.Errorf(nil, "pact retrieve request failed: invalid
params.")
- return &brokerpb.GetProviderConsumerVersionPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "Request
format invalid."),
- }, -1, nil
- }
- tenant := GetDefaultTenantProject()
- // Get provider microservice
- provider, err := serviceUtil.GetService(ctx, tenant, in.ProviderId)
- if err != nil {
- if errors.Is(err, datasource.ErrNoData) {
- PactLogger.Debug(fmt.Sprintf("pact retrieve failed,
providerId is %s: provider not exist.", in.ProviderId))
- return &brokerpb.GetProviderConsumerVersionPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal,
"Provider does not exist."),
- }, -1, nil
- }
- PactLogger.Error(fmt.Sprintf("pact retrieve failed, providerId
is %s: query provider failed.", in.ProviderId), err)
- return &brokerpb.GetProviderConsumerVersionPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "Query
provider failed."),
- }, -1, err
- }
- // Get consumer microservice
- consumer, err := serviceUtil.GetService(ctx, tenant, in.ConsumerId)
- if err != nil {
- if errors.Is(err, datasource.ErrNoData) {
- PactLogger.Debug(fmt.Sprintf("pact retrieve failed,
consumerId is %s: consumer not exist.", in.ConsumerId))
- return &brokerpb.GetProviderConsumerVersionPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal,
"Consumer does not exist."),
- }, -1, nil
- }
- PactLogger.Error(fmt.Sprintf("pact retrieve failed, consumerId
is %s: query consumer failed.", in.ConsumerId), err)
- return &brokerpb.GetProviderConsumerVersionPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "Query
consumer failed."),
- }, -1, err
- }
- // Get provider participant
- //providerParticipantKey := apt.GenerateBrokerParticipantKey(tenant,
provider.AppId, provider.ServiceName)
- providerParticipant, err := GetParticipant(ctx, tenant, provider.AppId,
provider.ServiceName)
- if err != nil || providerParticipant == nil {
- PactLogger.Errorf(nil, "pact retrieve failed, provider
participant %s cannot be searched.", in.ProviderId)
- return &brokerpb.GetProviderConsumerVersionPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "Provider
participant cannot be searched."),
- }, -1, err
- }
- // Get consumer participant
- //consumerParticipantKey := apt.GenerateBrokerParticipantKey(tenant,
consumer.AppId, consumer.ServiceName)
- consumerParticipant, err := GetParticipant(ctx, tenant, consumer.AppId,
consumer.ServiceName)
- if err != nil || consumerParticipant == nil {
- PactLogger.Errorf(nil, "pact retrieve failed, consumer
participant %s cannot be searched.", in.ConsumerId)
- return &brokerpb.GetProviderConsumerVersionPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "consumer
participant cannot be searched."),
- }, -1, err
- }
- // Get or create version
- //versionKey := apt.GenerateBrokerVersionKey(tenant, in.Version,
consumerParticipant.ID)
- version, err := GetVersion(ctx, tenant, in.Version,
consumerParticipant.Id)
- if err != nil || version == nil {
- PactLogger.Errorf(nil, "pact retrieve failed, version cannot be
searched.")
- return &brokerpb.GetProviderConsumerVersionPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "version
cannot be searched."),
- }, -1, err
- }
- // Get all pactversions and filter using the provider participant id
- pactVersionKey := util.StringJoin([]string{
- GetBrokerPactVersionKey(tenant),
- strconv.Itoa(int(version.Id))},
- "/")
- pactVersions, err := Store().PactVersion().Search(ctx,
- client.WithPrefix(),
- client.WithStrKey(pactVersionKey))
-
- if err != nil {
- return nil, -1, err
- }
- if len(pactVersions.Kvs) == 0 {
- PactLogger.Info("[RetrieveProviderPact] No pact version found,
sorry")
- return nil, -1, nil
- }
- pactIDs := make(map[int32]int32)
- for i := 0; i < len(pactVersions.Kvs); i++ {
- pactVersion := &brokerpb.PactVersion{}
- err = json.Unmarshal(pactVersions.Kvs[i].Value.([]byte),
pactVersion)
- if err != nil {
- return nil, -1, err
- }
- // Obviously true, but checking it anyways
- if pactVersion.VersionId == version.Id {
- pactid := pactVersion.PactId
- pactIDs[pactid] = pactid
- }
- }
- if len(pactIDs) == 0 {
- PactLogger.Errorf(nil, "pact retrieve failed, pact cannot be
found.")
- return &brokerpb.GetProviderConsumerVersionPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "pact
cannot be found."),
- }, -1, err
- }
- pactKey := util.StringJoin([]string{
- GetBrokerPactKey(tenant),
- strconv.Itoa(int(consumerParticipant.Id)),
- strconv.Itoa(int(providerParticipant.Id))},
- "/")
- pacts, err := Store().Pact().Search(ctx,
- client.WithStrKey(pactKey),
- client.WithPrefix())
-
- if err != nil {
- return nil, -1, err
- }
- if len(pacts.Kvs) == 0 {
- PactLogger.Info("[RetrieveProviderPact] No pact version found,
sorry")
- return nil, -1, nil
- }
- for i := 0; i < len(pacts.Kvs); i++ {
- pactObj := &brokerpb.Pact{}
- err = json.Unmarshal(pacts.Kvs[i].Value.([]byte), pactObj)
- if err != nil {
- return nil, -1, err
- }
- if _, ok := pactIDs[pactObj.Id]; ok {
- //PactLogger.Infof("pact retrieve succeeded, found
pact: %s", string(pactObj.Content))
- return &brokerpb.GetProviderConsumerVersionPactResponse{
- Response: pb.CreateResponse(pb.ResponseSuccess,
"pact found."),
- Pact: pactObj.Content,
- }, pactObj.Id, nil
- }
- }
- PactLogger.Errorf(nil, "pact retrieve failed, pact cannot be found.")
- return &brokerpb.GetProviderConsumerVersionPactResponse{
- Response: pb.CreateResponse(pb.ErrInternal, "pact cannot be
found."),
- }, -1, nil
-}
-
-func DeletePactData(ctx context.Context,
- in *brokerpb.BaseBrokerRequest) (*pb.Response, error) {
- //tenant := util.ParseTenantProject(ctx)
- allPactKey := GetBrokerRootKey() //GetBrokerVerificationKey("default")
//util.StringJoin([]string{ apt.GetRootKey(), apt.REGISTRY_PACT_ROOT_KEY }, "/")
-
- _, err := client.Instance().Do(ctx,
- client.DEL, client.WithStrKey(allPactKey), client.WithPrefix())
- if err != nil {
- return pb.CreateResponse(pb.ErrInternal, "error deleting
pacts."), err
- }
- return pb.CreateResponse(pb.ResponseSuccess, "deleting pacts
Succeed."), nil
-}