Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.18
require (
github.com/99designs/keyring v1.2.1
github.com/apache/pulsar-client-go v0.9.0
github.com/docker/docker v0.7.3-0.20190506211059-b20a14b54661
github.com/docker/go-connections v0.4.0
github.com/fatih/color v1.7.0
github.com/ghodss/yaml v1.0.0
Expand Down Expand Up @@ -34,7 +35,6 @@ require (
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible // indirect
github.com/docker/docker v0.7.3-0.20190506211059-b20a14b54661 // indirect
github.com/docker/go-units v0.3.3 // indirect
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
Expand Down
15 changes: 12 additions & 3 deletions pkg/bkctl/autorecovery/who_is_auditor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package autorecovery

import (
"context"
"fmt"
"testing"

"github.com/streamnative/pulsarctl/pkg/test/bookkeeper"
Expand Down Expand Up @@ -49,13 +50,21 @@ func TestWhoIsAuditor(t *testing.T) {
t.Fatal(err)
}

allBK := bk.GetAllBookieContainerID()
bkIP, err := bk.ContainerIP(ctx)
if err != nil {
t.Fatal(err)
}

httpAddr, err := bk.GetHTTPServiceURL(ctx)
bkPort := bk.GetBookieServicePortPort()
if err != nil {
t.Fatal(err)
}
auditor := fmt.Sprintf("%s:%d", bkIP, bkPort)

httpAddr, err := bk.GetHTTPServiceURL(ctx)
if err != nil {
t.Fatal(err)
}
args := []string{"--bookie-service-url", httpAddr, "who-is-auditor"}
out, execErr, nameErr, err := testAutoRecoveryCommands(whoIsAuditorCmd, args)
if err != nil {
Expand All @@ -68,5 +77,5 @@ func TestWhoIsAuditor(t *testing.T) {
t.Fatal(execErr)
}

assert.Contains(t, out.String(), allBK[0][:12])
assert.Contains(t, out.String(), auditor)
}
5 changes: 3 additions & 2 deletions pkg/bookkeeper/bkdata/ledger_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
package bkdata

type BookieSocketAddress struct {
Port int `json:"port"`
HostName string `json:"hostname"`
Port int `json:"port,omitempty"`
HostName string `json:"hostname,omitempty"`
ID string `json:"id,omitempty"`
}

type LedgerMetadata struct {
Expand Down
25 changes: 25 additions & 0 deletions pkg/test/base_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ package test
import (
"context"

"github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"github.com/pkg/errors"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
)
Expand Down Expand Up @@ -141,3 +143,26 @@ func (bc *BaseContainer) GetContainerID() string {
func (bc *BaseContainer) MappedPort(ctx context.Context, port string) (nat.Port, error) {
return bc.container.MappedPort(ctx, nat.Port(port))
}

func (bc *BaseContainer) ContainerIP(ctx context.Context) (string, error) {
c, err := client.NewClientWithOpts()
if err != nil {
return "", err
}

inspect, err := c.ContainerInspect(ctx, bc.container.GetContainerID())
if err != nil {
return "", err
}

ip := inspect.NetworkSettings.IPAddress
if ip != "" {
return ip, nil
}

for _, settings := range inspect.NetworkSettings.Networks {
return settings.IPAddress, nil
}

return "", errors.New("cannot get container ip address")
}
21 changes: 19 additions & 2 deletions pkg/test/bookkeeper/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"fmt"
"strconv"
"time"

"github.com/streamnative/pulsarctl/pkg/test"
"github.com/streamnative/pulsarctl/pkg/test/bookkeeper/containers"
Expand All @@ -31,7 +32,7 @@ import (

var (
LatestImage = "apache/bookkeeper:latest"
BookKeeper4_10_0 = "apache/bookkeeper:4.10.0"
BookKeeper4_10_0 = "apache/bookkeeper:4.14.3"
)

type ClusterDef struct {
Expand Down Expand Up @@ -99,7 +100,15 @@ func (c *ClusterDef) Start(ctx context.Context) error {
fmt.Println("BookKeeper metadata initialized successfully.")

for k, v := range c.bookieContainers {
err = v.Start(ctx)
retry := 0 // starting bk container sometimes fails.
for retry <= 5 {
err = v.Start(ctx)
if err == nil {
break
}
retry++
fmt.Printf("Retry start the %s at %s: %s\n", k, time.Now(), err)
}
if err != nil {
return errors.WithMessagef(err, "encountering errors when starting the bookie %s\n", k)
}
Expand Down Expand Up @@ -153,3 +162,11 @@ func (c *ClusterDef) GetAllBookieContainerID() []string {
}
return containerIDs
}

func (c *ClusterDef) ContainerIP(ctx context.Context) (string, error) {
return c.getABookie().ContainerIP(ctx)
}

func (c *ClusterDef) GetBookieServicePortPort() int {
return c.clusterSpec.BookieServicePort
}
2 changes: 1 addition & 1 deletion pkg/test/bookkeeper/containers/zookeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewZookeeperContainer(image, network string) *test.BaseContainer {
zookeeper.WithNetwork([]string{network})
zookeeper.WithNetworkAliases(map[string][]string{network: {ZookeeperName}})
zookeeper.WithCmd([]string{"zookeeper"})
zookeeper.WaitForLog("binding to port 0.0.0.0/0.0.0.0:2181")
zookeeper.WaitForLog("Started AdminServer")
return zookeeper
}

Expand Down
6 changes: 3 additions & 3 deletions test/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'
services:
zookeeper:
container_name: bk-zookeeper
image: "apache/bookkeeper:4.10.0"
image: "apache/bookkeeper:4.14.3"
hostname: zookeeper
entrypoint:
- /bin/bash
Expand All @@ -13,7 +13,7 @@ services:
depends_on:
- zookeeper
- bookie-init
image: "apache/bookkeeper:4.10.0"
image: "apache/bookkeeper:4.14.3"
hostname: bookie
links:
- zookeeper
Expand All @@ -32,7 +32,7 @@ services:
/opt/bookkeeper/bin/bookkeeper bookie
restart: on-failure
bookie-init:
image: "apache/bookkeeper:4.10.0"
image: "apache/bookkeeper:4.14.3"
hostname: bookie-client
links:
- zookeeper
Expand Down