refact(session connection): remove session connection state table (#4617)
* refact(session connection): remove session connection state table
This commit is contained in:
1 parent
eb6e1b558d
commit
2191aa1d03
27 files changed
+543
-729
No files matched your search
@@ -622,16 +622,13 @@ func (ws *workerServiceServer) AuthorizeConnection(ctx context.Context, req *pbs
|
||||
return nil, status.Errorf(codes.NotFound, "worker not found with name %q", req.GetWorkerId())
|
||||
}
|
||||
|
||||
connectionInfo, connStates, err := connectionRepo.AuthorizeConnection(ctx, req.GetSessionId(), w.GetPublicId())
|
||||
connectionInfo, err := connectionRepo.AuthorizeConnection(ctx, req.GetSessionId(), w.GetPublicId())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if connectionInfo == nil {
|
||||
return nil, status.Error(codes.Internal, "Invalid authorize connection response.")
|
||||
}
|
||||
if len(connStates) == 0 {
|
||||
return nil, status.Error(codes.Internal, "Invalid connection state in authorize response.")
|
||||
}
|
||||
|
||||
sessInfo, authzSummary, err := sessionRepo.LookupSession(ctx, req.GetSessionId())
|
||||
if err != nil {
|
||||
@@ -648,7 +645,7 @@ func (ws *workerServiceServer) AuthorizeConnection(ctx context.Context, req *pbs
|
||||
|
||||
ret := &pbs.AuthorizeConnectionResponse{
|
||||
ConnectionId: connectionInfo.GetPublicId(),
|
||||
Status: connStates[0].Status.ProtoVal(),
|
||||
Status: session.ConnectionStatusFromString(connectionInfo.Status).ProtoVal(),
|
||||
ConnectionsLeft: authzSummary.ConnectionLimit,
|
||||
Route: route,
|
||||
}
|
||||
@@ -680,7 +677,7 @@ func (ws *workerServiceServer) ConnectConnection(ctx context.Context, req *pbs.C
|
||||
return nil, status.Errorf(codes.Internal, "error getting session repo: %v", err)
|
||||
}
|
||||
|
||||
connectionInfo, connStates, err := connRepo.ConnectConnection(ctx, session.ConnectWith{
|
||||
connectionInfo, err := connRepo.ConnectConnection(ctx, session.ConnectWith{
|
||||
ConnectionId: req.GetConnectionId(),
|
||||
ClientTcpAddress: req.GetClientTcpAddress(),
|
||||
ClientTcpPort: req.GetClientTcpPort(),
|
||||
@@ -696,7 +693,7 @@ func (ws *workerServiceServer) ConnectConnection(ctx context.Context, req *pbs.C
|
||||
}
|
||||
|
||||
return &pbs.ConnectConnectionResponse{
|
||||
Status: connStates[0].Status.ProtoVal(),
|
||||
Status: session.ConnectionStatusFromString(connectionInfo.Status).ProtoVal(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -742,12 +739,9 @@ func (ws *workerServiceServer) CloseConnection(ctx context.Context, req *pbs.Clo
|
||||
if v.Connection == nil {
|
||||
return nil, status.Errorf(codes.Internal, "No connection found while closing one of the connection IDs: %v", closeIds)
|
||||
}
|
||||
if len(v.ConnectionStates) == 0 {
|
||||
return nil, status.Errorf(codes.Internal, "No connection states found while closing one of the connection IDs: %v", closeIds)
|
||||
}
|
||||
closeData = append(closeData, &pbs.CloseConnectionResponseData{
|
||||
ConnectionId: v.Connection.GetPublicId(),
|
||||
Status: v.ConnectionStates[0].Status.ProtoVal(),
|
||||
Status: v.ConnectionState.ProtoVal(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ func TestStatus(t *testing.T) {
|
||||
tofu := session.TestTofu(t)
|
||||
canceledSess, _, err = repo.ActivateSession(ctx, canceledSess.PublicId, canceledSess.Version, tofu)
|
||||
require.NoError(t, err)
|
||||
canceledConn, _, err := connRepo.AuthorizeConnection(ctx, canceledSess.PublicId, worker1.PublicId)
|
||||
canceledConn, err := connRepo.AuthorizeConnection(ctx, canceledSess.PublicId, worker1.PublicId)
|
||||
require.NoError(t, err)
|
||||
|
||||
canceledSess, err = repo.CancelSession(ctx, canceledSess.PublicId, canceledSess.Version)
|
||||
@@ -120,7 +120,7 @@ func TestStatus(t *testing.T) {
|
||||
s := NewWorkerServiceServer(serversRepoFn, workerAuthRepoFn, sessionRepoFn, connRepoFn, nil, new(sync.Map), kms, new(atomic.Int64), fce)
|
||||
require.NotNil(t, s)
|
||||
|
||||
connection, _, err := connRepo.AuthorizeConnection(ctx, sess.PublicId, worker1.PublicId)
|
||||
connection, err := connRepo.AuthorizeConnection(ctx, sess.PublicId, worker1.PublicId)
|
||||
require.NoError(t, err)
|
||||
|
||||
cases := []struct {
|
||||
@@ -562,7 +562,7 @@ func TestStatusSessionClosed(t *testing.T) {
|
||||
s := NewWorkerServiceServer(serversRepoFn, workerAuthRepoFn, sessionRepoFn, connRepoFn, nil, new(sync.Map), kms, new(atomic.Int64), fce)
|
||||
require.NotNil(t, s)
|
||||
|
||||
connection, _, err := connRepo.AuthorizeConnection(ctx, sess.PublicId, worker1.PublicId)
|
||||
connection, err := connRepo.AuthorizeConnection(ctx, sess.PublicId, worker1.PublicId)
|
||||
require.NoError(t, err)
|
||||
|
||||
cases := []struct {
|
||||
@@ -757,9 +757,9 @@ func TestStatusDeadConnection(t *testing.T) {
|
||||
s := NewWorkerServiceServer(serversRepoFn, workerAuthRepoFn, sessionRepoFn, connRepoFn, nil, new(sync.Map), kms, new(atomic.Int64), fce)
|
||||
require.NotNil(t, s)
|
||||
|
||||
connection, _, err := connRepo.AuthorizeConnection(ctx, sess.PublicId, worker1.PublicId)
|
||||
connection, err := connRepo.AuthorizeConnection(ctx, sess.PublicId, worker1.PublicId)
|
||||
require.NoError(t, err)
|
||||
deadConn, _, err := connRepo.AuthorizeConnection(ctx, sess2.PublicId, worker1.PublicId)
|
||||
deadConn, err := connRepo.AuthorizeConnection(ctx, sess2.PublicId, worker1.PublicId)
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, deadConn.PublicId, connection.PublicId)
|
||||
|
||||
@@ -823,12 +823,10 @@ func TestStatusDeadConnection(t *testing.T) {
|
||||
),
|
||||
)
|
||||
|
||||
gotConn, states, err := connRepo.LookupConnection(ctx, deadConn.PublicId)
|
||||
gotConn, err := connRepo.LookupConnection(ctx, deadConn.PublicId)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, session.ConnectionSystemError, session.ClosedReason(gotConn.ClosedReason))
|
||||
assert.Equal(t, 2, len(states))
|
||||
assert.Nil(t, states[0].EndTime)
|
||||
assert.Equal(t, session.StatusClosed, states[0].Status)
|
||||
assert.Equal(t, session.StatusClosed, session.ConnectionStatusFromString(gotConn.Status))
|
||||
}
|
||||
|
||||
func TestStatusWorkerWithKeyId(t *testing.T) {
|
||||
@@ -927,7 +925,7 @@ func TestStatusWorkerWithKeyId(t *testing.T) {
|
||||
s := NewWorkerServiceServer(serversRepoFn, workerAuthRepoFn, sessionRepoFn, connRepoFn, nil, new(sync.Map), kms, new(atomic.Int64), fce)
|
||||
require.NotNil(t, s)
|
||||
|
||||
connection, _, err := connRepo.AuthorizeConnection(ctx, sess.PublicId, worker1.PublicId)
|
||||
connection, err := connRepo.AuthorizeConnection(ctx, sess.PublicId, worker1.PublicId)
|
||||
require.NoError(t, err)
|
||||
|
||||
cases := []struct {
|
||||
|
||||
Reference in new issue
Block a user