Skip to content

Commit

Permalink
✨ Avoid calling the document store for image sets.
Browse files Browse the repository at this point in the history
Using the document store to discover image model UUIDs for republishing is only applicable if the image set has been published successfully to at least one environment. Although simply generating the alternative UUID when it's not found directly may seem less robust, the probability that we find and republish the wrong piece of content in this case is vanishingly small.
  • Loading branch information
Keith Hatton committed Feb 12, 2018
1 parent a1dca23 commit 66154eb
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 15 deletions.
6 changes: 1 addition & 5 deletions docStoreClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ import (
log "github.com/sirupsen/logrus"
)

type docStoreClient interface {
GetImageSetsModelUUID(setUUID, tid string) (found bool, modelUUID string, err error)
}

type httpDocStore struct {
httpClient *http.Client
docStoreAddressBase string
authHeader string
}

func newHTTPDocStore(httpClient *http.Client, docStoreAddressBase, authHeader string) (*httpDocStore, error) {
func newHTTPDocStore(httpClient *http.Client, docStoreAddressBase, authHeader string) (imageSetUUIDResolver, error) {
return &httpDocStore{
httpClient: httpClient,
docStoreAddressBase: docStoreAddressBase,
Expand Down
22 changes: 22 additions & 0 deletions imageSetResolver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"github.com/Financial-Times/uuid-utils-go"
)

type imageSetUUIDResolver interface {
GetImageSetsModelUUID(setUUID, tid string) (found bool, modelUUID string, err error)
}

type uuidImageSetResolver struct {
}

func newUUIDImageSetResolver() imageSetUUIDResolver {
return &uuidImageSetResolver{}
}

func (r *uuidImageSetResolver) GetImageSetsModelUUID(setUUID, tid string) (found bool, modelUUID string, err error) {
requestedUUID, _ := uuidutils.NewUUIDFromString(setUUID)
derivedUUID, _ := uuidutils.NewUUIDDeriverWith(uuidutils.IMAGE_SET).From(requestedUUID)
return true, derivedUUID.String(), nil
}
18 changes: 18 additions & 0 deletions imageSetResolver_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestUuidImageSetResolver(t *testing.T) {
r := newUUIDImageSetResolver()

imageSetUUID := "9f365884-0c25-11e8-24ad-bec2279df517"

found, imageModelUUID, err := r.GetImageSetsModelUUID(imageSetUUID, "tid_test")
assert.True(t, found, "found image model UUID")
assert.Equal(t, "9f365884-0c25-11e8-bacb-2958fde95e5e", imageModelUUID, "image model UUID")
assert.NoError(t, err)
}
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,15 @@ func main() {
httpClient := setupHTTPClient()
nativeStoreClient := newNativeStoreClient(httpClient, "https://"+*sourceEnvHost+"/__nativerw/", "Basic "+base64.StdEncoding.EncodeToString([]byte(*sourceAuth)))
notifierClient, err := newHTTPNotifier(httpClient, "https://"+*targetEnvHost+"/__", "Basic "+base64.StdEncoding.EncodeToString([]byte(*targetAuth)))
docStoreClient, err := newHTTPDocStore(httpClient, "https://"+*deliveryEnvHost+"/__document-store-api/content", "Basic "+base64.StdEncoding.EncodeToString([]byte(*deliveryAuth)))
var imageSetResolver imageSetUUIDResolver
if *deliveryEnvHost == "" || *deliveryAuth == "" {
imageSetResolver = newUUIDImageSetResolver()
} else {
imageSetResolver, err = newHTTPDocStore(httpClient, "https://"+*deliveryEnvHost+"/__document-store-api/content", "Basic "+base64.StdEncoding.EncodeToString([]byte(*deliveryAuth)))
}
rateLimit := time.Duration(*rateLimitMs) * time.Millisecond
uuidCollectionRepublisher := newNotifyingUCRepublisher(notifierClient, nativeStoreClient, rateLimit)
uuidRepublisher := newNotifyingUUIDRepublisher(uuidCollectionRepublisher, docStoreClient, defaultCollections)
uuidRepublisher := newNotifyingUUIDRepublisher(uuidCollectionRepublisher, imageSetResolver, defaultCollections)
var republisher bulkRepublisher
if *parallelism > 1 {
republisher = newNotifyingParallelRepublisher(uuidRepublisher, *parallelism)
Expand Down
16 changes: 8 additions & 8 deletions uuidRepublisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ type uuidRepublisher interface {
}

type notifyingUUIDRepublisher struct {
ucRepublisher uuidCollectionRepublisher
docStoreClient docStoreClient
collections map[string]targetSystem
ucRepublisher uuidCollectionRepublisher
imageSetResolver imageSetUUIDResolver
collections map[string]targetSystem
}

func newNotifyingUUIDRepublisher(uuidCollectionRepublisher uuidCollectionRepublisher, docStoreClient docStoreClient, collections map[string]targetSystem) *notifyingUUIDRepublisher {
func newNotifyingUUIDRepublisher(uuidCollectionRepublisher uuidCollectionRepublisher, imageSetResolver imageSetUUIDResolver, collections map[string]targetSystem) *notifyingUUIDRepublisher {
return &notifyingUUIDRepublisher{
ucRepublisher: uuidCollectionRepublisher,
docStoreClient: docStoreClient,
collections: collections,
ucRepublisher: uuidCollectionRepublisher,
imageSetResolver: imageSetResolver,
collections: collections,
}
}

Expand Down Expand Up @@ -49,7 +49,7 @@ func (r *notifyingUUIDRepublisher) Republish(uuid, tidPrefix string, republishSc

if !isFoundInAnyCollection && isScopedInAnyCollection {
tid := tidPrefix + transactionidutils.NewTransactionID()
isFoundAsImageSet, imageModelUUID, err := r.docStoreClient.GetImageSetsModelUUID(uuid, tid)
isFoundAsImageSet, imageModelUUID, err := r.imageSetResolver.GetImageSetsModelUUID(uuid, tid)
if err != nil {
errs = append(errs, fmt.Errorf("couldn't check if it's an ImageSet containing an image inside because of an error uuid=%v tid=%v %v", uuid, tid, err))
return nil, errs
Expand Down
18 changes: 18 additions & 0 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
"version": "v0.2.0",
"versionExact": "v0.2.0"
},
{
"checksumSHA1": "SFO+8Q3GAkd8e/LaTdsJRu4OZLA=",
"path": "github.com/Financial-Times/uuid-utils-go",
"revision": "e22658edd0f130936e99079bf844bde7087c914c",
"revisionTime": "2017-05-16T11:04:27Z",
"version": "1.0.1",
"versionExact": "1.0.1"
},
{
"checksumSHA1": "O/WTQh5sctzo4/59PLsV1VXW50U=",
"path": "github.com/Financial-Times/workbalancer",
Expand Down Expand Up @@ -66,6 +74,12 @@
"version": "v1.2.1",
"versionExact": "v1.2.1"
},
{
"checksumSHA1": "Zqzba4X+lRAiAEn13WdFoQpn+RI=",
"path": "github.com/willf/bitset",
"revision": "1a37ad96e8c1a11b20900a232874843b5174221f",
"revisionTime": "2017-09-05T00:26:39Z"
},
{
"checksumSHA1": "6U7dCaxxIMjf5V02iWgyAwppczw=",
"path": "golang.org/x/crypto/ssh/terminal",
Expand All @@ -89,6 +103,10 @@
"path": "golang.org/x/sys/windows",
"revision": "37707fdb30a5b38865cfb95e5aab41707daec7fd",
"revisionTime": "2018-02-02T13:35:31Z"
},
{
"path": "math/bits",
"revision": ""
}
],
"rootPath": "github.com/Financial-Times/publish-failure-resolver-go"
Expand Down

0 comments on commit 66154eb

Please sign in to comment.