Refactor storage to support shallow types.

Add Client to storage.
Fix client resizing issues.
This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-09-01 20:12:19 -03:00
parent 4b00a9c0eb
commit 954c52471b
25 changed files with 1005 additions and 563 deletions

View File

@@ -161,9 +161,14 @@ func (s *scheduler) processSession(ctx context.Context, session *types.Session)
return
}
instances, err := s.storage.InstanceFindBySessionId(updatedSession.Id)
if err != nil {
log.Printf("Couldn't find instances for session [%s]. Got: %v\n", updatedSession.Id, err)
return
}
wg := sync.WaitGroup{}
wg.Add(len(updatedSession.Instances))
for _, ins := range updatedSession.Instances {
wg.Add(len(instances))
for _, ins := range instances {
go func(ins *types.Instance) {
s.processInstance(ctx, ins)
wg.Done()

View File

@@ -45,16 +45,19 @@ func TestNew(t *testing.T) {
s := &types.Session{
Id: "aaabbbccc",
ExpiresAt: time.Now().Add(time.Hour),
Instances: map[string]*types.Instance{
"node1": &types.Instance{
Name: "node1",
IP: "10.0.0.1",
},
},
}
i := &types.Instance{
SessionId: s.Id,
Name: "node1",
IP: "10.0.0.1",
}
err := store.SessionPut(s)
assert.Nil(t, err)
err = store.InstancePut(i)
assert.Nil(t, err)
sch, err := NewScheduler(store, event.NewLocalBroker(), &pwd.Mock{})
assert.Nil(t, err)
assert.Len(t, sch.scheduledSessions, 1)
@@ -99,16 +102,19 @@ func TestStart(t *testing.T) {
s := &types.Session{
Id: "aaabbbccc",
ExpiresAt: time.Now().Add(time.Hour),
Instances: map[string]*types.Instance{
"node1": &types.Instance{
Name: "node1",
IP: "10.0.0.1",
},
},
}
i := &types.Instance{
SessionId: s.Id,
Name: "node1",
IP: "10.0.0.1",
}
err := store.SessionPut(s)
assert.Nil(t, err)
err = store.InstancePut(i)
assert.Nil(t, err)
sch, err := NewScheduler(store, event.NewLocalBroker(), &pwd.Mock{})
assert.Nil(t, err)