From 17eace8342412ac9965c1b345866f1fc15ced9de Mon Sep 17 00:00:00 2001 From: John Date: Wed, 11 Dec 2024 10:43:11 -0700 Subject: [PATCH] Add naming changes --- pkg/abstractions/common/instance.go | 13 +++++-------- pkg/common/keys.go | 6 +++--- pkg/repository/base.go | 8 ++++---- pkg/repository/container_redis.go | 12 ++++++------ pkg/repository/events.go | 2 +- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/pkg/abstractions/common/instance.go b/pkg/abstractions/common/instance.go index a111afefb..242376e89 100644 --- a/pkg/abstractions/common/instance.go +++ b/pkg/abstractions/common/instance.go @@ -298,9 +298,8 @@ func (i *AutoscaledInstance) State() (*AutoscaledInstanceState, error) { func (i *AutoscaledInstance) HandleDeploymentNotHealthy(stubId, currentState, reason string, containers []string) { var state string - state, err := i.ContainerRepo.GetStubUnhealthyState(stubId) + state, err := i.ContainerRepo.GetStubState(stubId) if err != nil { - log.Printf("<%s> failed to get unhealthy state\n", i.Name) return } @@ -308,25 +307,23 @@ func (i *AutoscaledInstance) HandleDeploymentNotHealthy(stubId, currentState, re return } - err = i.ContainerRepo.SetStubUnhealthyState(stubId, currentState) + err = i.ContainerRepo.SetStubState(stubId, currentState) if err != nil { - log.Printf("<%s> failed to set unhealthy state\n", i.Name) return } - go i.EventRepo.PushStubStateNotHealthy(i.Workspace.ExternalId, stubId, currentState, state, reason, containers) + go i.EventRepo.PushStubStateUnhealthy(i.Workspace.ExternalId, stubId, currentState, state, reason, containers) } func (i *AutoscaledInstance) HandleDeploymentHealthy(stubId string) { var state string - state, err := i.ContainerRepo.GetStubUnhealthyState(stubId) + state, err := i.ContainerRepo.GetStubState(stubId) if err != nil || state == types.StubStateHealthy { return } - err = i.ContainerRepo.DeleteStubUnhealthyState(stubId) + err = i.ContainerRepo.DeleteStubState(stubId) if err != nil { - log.Printf("<%s> failed to set unhealthy state\n", i.Name) return } diff --git a/pkg/common/keys.go b/pkg/common/keys.go index e2887e043..f54d2535d 100644 --- a/pkg/common/keys.go +++ b/pkg/common/keys.go @@ -21,7 +21,7 @@ var ( schedulerContainerLock string = "scheduler:container:lock:%s" schedulerContainerExitCode string = "scheduler:container:exit_code:%s" schedulerCheckpointState string = "scheduler:checkpoint_state:%s:%s" - schedulerStubUnhealthyState string = "scheduler:stub:unhealthy_state:%s" + schedulerStubState string = "scheduler:stub:state:%s" ) var ( @@ -147,8 +147,8 @@ func (rk *redisKeys) SchedulerCheckpointState(workspaceName, checkpointId string return fmt.Sprintf(schedulerCheckpointState, workspaceName, checkpointId) } -func (rk *redisKeys) SchedulerStubUnhealthyState(stubId string) string { - return fmt.Sprintf(schedulerStubUnhealthyState, stubId) +func (rk *redisKeys) SchedulerStubState(stubId string) string { + return fmt.Sprintf(schedulerStubState, stubId) } // Gateway keys diff --git a/pkg/repository/base.go b/pkg/repository/base.go index 2907f670f..54651e36c 100755 --- a/pkg/repository/base.go +++ b/pkg/repository/base.go @@ -58,9 +58,9 @@ type ContainerRepository interface { GetFailedContainersByStubId(stubId string) ([]string, error) UpdateCheckpointState(workspaceName, checkpointId string, checkpointState *types.CheckpointState) error GetCheckpointState(workspaceName, checkpointId string) (*types.CheckpointState, error) - GetStubUnhealthyState(stubId string) (string, error) - SetStubUnhealthyState(stubId, state string) error - DeleteStubUnhealthyState(stubId string) error + GetStubState(stubId string) (string, error) + SetStubState(stubId, state string) error + DeleteStubState(stubId string) error } type WorkspaceRepository interface { @@ -183,7 +183,7 @@ type EventRepository interface { PushRunStubEvent(workspaceId string, stub *types.Stub) PushTaskUpdatedEvent(task *types.TaskWithRelated) PushTaskCreatedEvent(task *types.TaskWithRelated) - PushStubStateNotHealthy(workspaceId string, stubId string, currentState, previousState string, reason string, failedContainers []string) + PushStubStateUnhealthy(workspaceId string, stubId string, currentState, previousState string, reason string, failedContainers []string) PushStubStateHealthy(workspaceId string, stubId string, previousState string) } diff --git a/pkg/repository/container_redis.go b/pkg/repository/container_redis.go index c09a348e8..b003e4701 100644 --- a/pkg/repository/container_redis.go +++ b/pkg/repository/container_redis.go @@ -457,8 +457,8 @@ func (cr *ContainerRedisRepository) GetCheckpointState(workspaceName, checkpoint return state, nil } -func (cr *ContainerRedisRepository) GetStubUnhealthyState(stubId string) (string, error) { - stateKey := common.RedisKeys.SchedulerStubUnhealthyState(stubId) +func (cr *ContainerRedisRepository) GetStubState(stubId string) (string, error) { + stateKey := common.RedisKeys.SchedulerStubState(stubId) state, err := cr.rdb.Get(context.TODO(), stateKey).Result() if err != nil { if err == redis.Nil { @@ -472,12 +472,12 @@ func (cr *ContainerRedisRepository) GetStubUnhealthyState(stubId string) (string var unhealthyStateTTL = 10 * time.Minute -func (cr *ContainerRedisRepository) SetStubUnhealthyState(stubId, state string) error { - stateKey := common.RedisKeys.SchedulerStubUnhealthyState(stubId) +func (cr *ContainerRedisRepository) SetStubState(stubId, state string) error { + stateKey := common.RedisKeys.SchedulerStubState(stubId) return cr.rdb.SetEx(context.TODO(), stateKey, state, unhealthyStateTTL).Err() } -func (cr *ContainerRedisRepository) DeleteStubUnhealthyState(stubId string) error { - stateKey := common.RedisKeys.SchedulerStubUnhealthyState(stubId) +func (cr *ContainerRedisRepository) DeleteStubState(stubId string) error { + stateKey := common.RedisKeys.SchedulerStubState(stubId) return cr.rdb.Del(context.TODO(), stateKey).Err() } diff --git a/pkg/repository/events.go b/pkg/repository/events.go index 87d9db93d..f1470dd3e 100644 --- a/pkg/repository/events.go +++ b/pkg/repository/events.go @@ -281,7 +281,7 @@ func (t *TCPEventClientRepo) PushTaskCreatedEvent(task *types.TaskWithRelated) { ) } -func (t *TCPEventClientRepo) PushStubStateNotHealthy(workspaceId string, stubId string, currentState string, previousState string, reason string, failedContainers []string) { +func (t *TCPEventClientRepo) PushStubStateUnhealthy(workspaceId string, stubId string, currentState string, previousState string, reason string, failedContainers []string) { t.pushEvent( fmt.Sprintf("stub.state.%s", strings.ToLower(currentState)), types.EventStubStateSchemaVersion,