Skip to content

Commit

Permalink
chore: remove module name from deployment (#3987)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmakine authored Jan 13, 2025
1 parent 24a89bf commit fec3263
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
17 changes: 8 additions & 9 deletions backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (s *Service) Status(ctx context.Context, req *connect.Request[ftlv1.StatusR
return &ftlv1.StatusResponse_Deployment{
Key: d.Key.String(),
Language: d.Language,
Name: d.Module,
Name: d.Schema.Name,
MinReplicas: int32(d.MinReplicas),
Replicas: replicas[d.Key.String()],
Schema: d.Schema.ToProto(),
Expand Down Expand Up @@ -416,7 +416,7 @@ func (s *Service) ReplaceDeploy(ctx context.Context, c *connect.Request[ftlv1.Re
// TODO: remove all this, it needs to be event driven
var oldDeployment *state.Deployment
for _, dep := range view.GetActiveDeployments() {
if dep.Module == newDeployment.Module {
if dep.Schema.Name == newDeployment.Schema.Name {
oldDeployment = dep
break
}
Expand Down Expand Up @@ -445,7 +445,7 @@ func (s *Service) ReplaceDeploy(ctx context.Context, c *connect.Request[ftlv1.Re
s.timelineClient.Publish(ctx, timelineclient.DeploymentCreated{
DeploymentKey: newDeploymentKey,
Language: newDeployment.Language,
ModuleName: newDeployment.Module,
ModuleName: newDeployment.Schema.Name,
MinReplicas: minReplicas,
ReplacedDeployment: replacedDeploymentKey,
})
Expand Down Expand Up @@ -626,7 +626,7 @@ func (s *Service) GetDeploymentContext(ctx context.Context, req *connect.Request
if err != nil {
return fmt.Errorf("could not get deployment: %w", err)
}
module := deployment.Module
module := deployment.Schema.Name

// Initialize checksum to -1; a zero checksum does occur when the context contains no settings
lastChecksum := int64(-1)
Expand Down Expand Up @@ -925,7 +925,6 @@ func (s *Service) CreateDeployment(ctx context.Context, req *connect.Request[ftl

dkey := key.NewDeploymentKey(module.Name)
err = s.schemaState.Publish(ctx, &state.DeploymentCreatedEvent{
Module: module.Name,
Key: dkey,
CreatedAt: time.Now(),
Schema: module,
Expand All @@ -949,7 +948,7 @@ func (s *Service) validateModuleSchema(ctx context.Context, module *schema.Modul
return nil, fmt.Errorf("failed to get schema state: %w", err)
}
existingModules := view.GetActiveDeployments()
schemaMap := ftlmaps.FromSlice(maps.Values(existingModules), func(el *state.Deployment) (string, *schema.Module) { return el.Module, el.Schema })
schemaMap := ftlmaps.FromSlice(maps.Values(existingModules), func(el *state.Deployment) (string, *schema.Module) { return el.Schema.Name, el.Schema })
schemaMap[module.Name] = module
fullSchema := &schema.Schema{Modules: maps.Values(schemaMap)}
schema, err := schema.ValidateModuleInSchema(fullSchema, optional.Some[*schema.Module](module))
Expand Down Expand Up @@ -1070,7 +1069,7 @@ func (s *Service) watchModuleChanges(ctx context.Context, sendChange func(respon
switch event := notification.(type) {
case *state.DeploymentCreatedEvent:
err := sendChange(&ftlv1.PullSchemaResponse{ //nolint:forcetypeassert
ModuleName: event.Module,
ModuleName: event.Schema.Name,
DeploymentKey: proto.String(event.Key.String()),
Schema: event.Schema.ToProto(),
ChangeType: ftlv1.DeploymentChangeType_DEPLOYMENT_CHANGE_TYPE_ADDED,
Expand All @@ -1089,7 +1088,7 @@ func (s *Service) watchModuleChanges(ctx context.Context, sendChange func(respon
continue
}
err = sendChange(&ftlv1.PullSchemaResponse{ //nolint:forcetypeassert
ModuleName: dep.Module,
ModuleName: dep.Schema.Name,
DeploymentKey: proto.String(event.Key.String()),
Schema: dep.Schema.ToProto(),
ChangeType: ftlv1.DeploymentChangeType_DEPLOYMENT_CHANGE_TYPE_REMOVED,
Expand All @@ -1109,7 +1108,7 @@ func (s *Service) watchModuleChanges(ctx context.Context, sendChange func(respon
continue
}
err = sendChange(&ftlv1.PullSchemaResponse{ //nolint:forcetypeassert
ModuleName: dep.Module,
ModuleName: dep.Schema.Name,
DeploymentKey: proto.String(event.Key.String()),
Schema: event.Schema.ToProto(),
ChangeType: ftlv1.DeploymentChangeType_DEPLOYMENT_CHANGE_TYPE_CHANGED,
Expand Down
3 changes: 0 additions & 3 deletions backend/controller/state/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

type Deployment struct {
Key key.Deployment
Module string
Schema *schema.Module
MinReplicas int
CreatedAt time.Time
Expand Down Expand Up @@ -58,7 +57,6 @@ var _ SchemaEvent = (*DeploymentReplicasUpdatedEvent)(nil)
type DeploymentCreatedEvent struct {
Key key.Deployment
CreatedAt time.Time
Module string
Schema *schema.Module
Language string
}
Expand All @@ -71,7 +69,6 @@ func (r *DeploymentCreatedEvent) Handle(t SchemaState) (SchemaState, error) {
Key: r.Key,
CreatedAt: r.CreatedAt,
Schema: r.Schema,
Module: r.Module,
Language: r.Language,
}
t.deployments[r.Key] = &n
Expand Down
5 changes: 2 additions & 3 deletions backend/controller/state/eventextractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func EventExtractor(diff tuple.Pair[SchemaState, SchemaState]) iter.Seq[SchemaEv
pd, ok := previousAll[deployment.Key]
if !ok {
events = append(events, &DeploymentCreatedEvent{
Module: deployment.Module,
Key: deployment.Key,
CreatedAt: deployment.CreatedAt,
Schema: deployment.Schema,
Expand All @@ -38,11 +37,11 @@ func EventExtractor(diff tuple.Pair[SchemaState, SchemaState]) iter.Seq[SchemaEv
currentAll := current.GetDeployments()
currentModules := map[string]bool{}
for _, deployment := range currentAll {
currentModules[deployment.Module] = true
currentModules[deployment.Schema.Name] = true
}
for _, deployment := range previous.GetActiveDeployments() {
if _, ok := currentActive[deployment.Key]; !ok {
_, ok2 := currentModules[deployment.Module]
_, ok2 := currentModules[deployment.Schema.Name]
events = append(events, &DeploymentDeactivatedEvent{
Key: deployment.Key,
ModuleRemoved: !ok2,
Expand Down
10 changes: 3 additions & 7 deletions backend/controller/state/eventextractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestEventExtractor(t *testing.T) {
current: SchemaState{
deployments: map[key.Deployment]*Deployment{
deploymentKey(t, "dpl-test-sjkfislfjslfas"): {
Module: "test",
Key: deploymentKey(t, "dpl-test-sjkfislfjslfas"),
CreatedAt: now,
Schema: &schema.Module{Name: "test"},
Expand All @@ -36,7 +35,6 @@ func TestEventExtractor(t *testing.T) {
},
want: []SchemaEvent{
&DeploymentCreatedEvent{
Module: "test",
Key: deploymentKey(t, "dpl-test-sjkfislfjslfas"),
CreatedAt: now,
Schema: &schema.Module{Name: "test"},
Expand All @@ -49,7 +47,6 @@ func TestEventExtractor(t *testing.T) {
previous: SchemaState{
deployments: map[key.Deployment]*Deployment{
deploymentKey(t, "dpl-test-sjkfislfjslfas"): {
Module: "test",
Key: deploymentKey(t, "dpl-test-sjkfislfjslfas"),
CreatedAt: now,
Schema: &schema.Module{Name: "test"},
Expand All @@ -60,7 +57,6 @@ func TestEventExtractor(t *testing.T) {
current: SchemaState{
deployments: map[key.Deployment]*Deployment{
deploymentKey(t, "dpl-test-sjkfislfjslfas"): {
Module: "test",
Key: deploymentKey(t, "dpl-test-sjkfislfjslfas"),
Schema: &schema.Module{Name: "test", Metadata: []schema.Metadata{&schema.MetadataArtefact{}}},
},
Expand All @@ -78,7 +74,7 @@ func TestEventExtractor(t *testing.T) {
previous: SchemaState{
deployments: map[key.Deployment]*Deployment{
deploymentKey(t, "dpl-test-sjkfislfjslfas"): {
Module: "test",
Schema: &schema.Module{Name: "test"},
Key: deploymentKey(t, "dpl-test-sjkfislfjslfas"),
},
},
Expand All @@ -89,7 +85,7 @@ func TestEventExtractor(t *testing.T) {
current: SchemaState{
deployments: map[key.Deployment]*Deployment{
deploymentKey(t, "dpl-test-sjkfislfjslfas"): {
Module: "test",
Schema: &schema.Module{Name: "test"},
Key: deploymentKey(t, "dpl-test-sjkfislfjslfas"),
},
},
Expand All @@ -106,7 +102,7 @@ func TestEventExtractor(t *testing.T) {
previous: SchemaState{
deployments: map[key.Deployment]*Deployment{
deploymentKey(t, "dpl-test-sjkfislfjslfaa"): {
Module: "test",
Schema: &schema.Module{Name: "test"},
Key: deploymentKey(t, "dpl-test-sjkfislfjslfaa"),
},
},
Expand Down

0 comments on commit fec3263

Please sign in to comment.