Skip to content

Commit 3a0f4a2

Browse files
ThisIsClarkwisererik
authored andcommitted
Support pool status (#1022)
1 parent 85238a2 commit 3a0f4a2

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

pkg/dock/discovery/discovery.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ import (
3939
uuid "github.com/satori/go.uuid"
4040
)
4141

42+
const (
43+
availableStatus = "available"
44+
unavailableStatus = "unavailable"
45+
)
46+
4247
type Context struct {
4348
StopChan chan bool
4449
ErrChan chan error
@@ -135,6 +140,7 @@ func (pdd *provisionDockDiscoverer) Discover() error {
135140
// Clear existing pool info
136141
pdd.pols = pdd.pols[:0]
137142
var pols []*model.StoragePoolSpec
143+
var polsInDb []*model.StoragePoolSpec
138144
var err error
139145
for _, dck := range pdd.dcks {
140146
// Call function of StorageDrivers configured by storage drivers.
@@ -145,6 +151,7 @@ func (pdd *provisionDockDiscoverer) Discover() error {
145151
for _, pol := range pols {
146152
log.Infof("Backend %s discovered pool %s", dck.DriverName, pol.Name)
147153
pol.DockId = dck.Id
154+
pol.Status = availableStatus
148155
}
149156
} else {
150157
d := drivers.Init(dck.DriverName)
@@ -162,6 +169,7 @@ func (pdd *provisionDockDiscoverer) Discover() error {
162169
pol.DockId = dck.Id
163170
pol.ReplicationType = replicationType
164171
pol.ReplicationDriverName = replicationDriverName
172+
pol.Status = availableStatus
165173
}
166174
}
167175
if err != nil {
@@ -175,8 +183,24 @@ func (pdd *provisionDockDiscoverer) Discover() error {
175183

176184
pdd.pols = append(pdd.pols, pols...)
177185
}
186+
ctx := c.NewAdminContext()
187+
polsInDb, err = pdd.c.ListPools(ctx)
188+
if err != nil {
189+
return fmt.Errorf("can not read pools in db")
190+
}
191+
dbPolsMap := make(map[string]*model.StoragePoolSpec)
192+
for _, polInDb := range polsInDb {
193+
dbPolsMap[polInDb.Id] = polInDb
194+
}
195+
for _, pol := range pdd.pols {
196+
delete(dbPolsMap, pol.Id)
197+
}
198+
for _, unavailablePol := range dbPolsMap {
199+
unavailablePol.Status = unavailableStatus
200+
pdd.pols = append(pdd.pols, unavailablePol)
201+
}
178202
if len(pdd.pols) == 0 {
179-
return fmt.Errorf("There is no pool can be found.")
203+
return fmt.Errorf("there is no pool can be found")
180204
}
181205

182206
return nil

pkg/dock/discovery/discovery_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,13 @@ func TestDiscover(t *testing.T) {
8080
fdd.dcks = append(fdd.dcks, &SampleDocks[i])
8181
}
8282
for i := range SamplePools {
83+
fdd.pols = append(fdd.pols, &SamplePools[i])
8384
expected = append(expected, &SamplePools[i])
8485
}
86+
mockClient := new(dbtest.Client)
87+
mockClient.On("ListPools", c.NewAdminContext()).Return(fdd.pols, nil)
88+
fdd.c = mockClient
89+
8590
if err := fdd.Discover(); err != nil {
8691
t.Errorf("Failed to discoverer pools: %v\n", err)
8792
}

0 commit comments

Comments
 (0)