Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
[
[
{
"type": "create",
"resource_id": "swarm.network::database-id",
"reason": "does_not_exist",
"diff": null
},
{
"type": "create",
"resource_id": "swarm.service_user_role::database-id-test-svc-host-1-id",
"reason": "does_not_exist",
"diff": null
}
],
[
{
"type": "create",
"resource_id": "swarm.service_instance_spec::database-id-test-svc-host-1-id",
"reason": "does_not_exist",
"diff": null
}
],
[
{
"type": "create",
"resource_id": "swarm.service_instance::database-id-test-svc-host-1-id",
"reason": "does_not_exist",
"diff": null
}
],
[
{
"type": "create",
"resource_id": "monitor.service_instance::database-id-test-svc-host-1-id",
"reason": "does_not_exist",
"diff": null
}
]
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
[
[
{
"type": "delete",
"resource_id": "monitor.service_instance::database-id-test-svc-host-1-id",
"diff": null
}
],
[
{
"type": "delete",
"resource_id": "swarm.service_instance::database-id-test-svc-host-1-id",
"diff": null
}
],
[
{
"type": "delete",
"resource_id": "swarm.service_instance_spec::database-id-test-svc-host-1-id",
"diff": null
}
],
[
{
"type": "delete",
"resource_id": "swarm.network::database-id",
"diff": null
},
{
"type": "delete",
"resource_id": "swarm.service_user_role::database-id-test-svc-host-1-id",
"diff": null
}
]
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[
[
[
{
"type": "create",
"resource_id": "orchestrator.resource::n1-instance-1-dep-1-id",
"reason": "does_not_exist",
"diff": null
}
],
[
{
"type": "create",
"resource_id": "database.instance::n1-instance-1-id",
"reason": "does_not_exist",
"diff": null
}
],
[
{
"type": "create",
"resource_id": "database.node::n1",
"reason": "does_not_exist",
"diff": null
},
{
"type": "create",
"resource_id": "monitor.instance::n1-instance-1-id",
"reason": "does_not_exist",
"diff": null
}
]
],
[
[
{
"type": "create",
"resource_id": "swarm.network::database-id",
"reason": "does_not_exist",
"diff": null
},
{
"type": "create",
"resource_id": "swarm.service_user_role::database-id-test-svc-host-1-id",
"reason": "does_not_exist",
"diff": null
}
],
[
{
"type": "create",
"resource_id": "swarm.service_instance_spec::database-id-test-svc-host-1-id",
"reason": "does_not_exist",
"diff": null
}
],
[
{
"type": "create",
"resource_id": "swarm.service_instance::database-id-test-svc-host-1-id",
"reason": "does_not_exist",
"diff": null
}
],
[
{
"type": "create",
"resource_id": "monitor.service_instance::database-id-test-svc-host-1-id",
"reason": "does_not_exist",
"diff": null
}
]
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
[
[
{
"type": "create",
"resource_id": "orchestrator.resource::n1-instance-1-dep-2-id",
"reason": "does_not_exist",
"diff": null
}
],
[
{
"type": "update",
"resource_id": "database.instance::n1-instance-1-id",
"reason": "dependency_updated",
"diff": null
}
],
[
{
"type": "update",
"resource_id": "database.node::n1",
"reason": "dependency_updated",
"diff": null
},
{
"type": "update",
"resource_id": "monitor.instance::n1-instance-1-id",
"reason": "dependency_updated",
"diff": null
}
]
]
]
150 changes: 150 additions & 0 deletions server/internal/database/operations/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/pgEdge/control-plane/server/internal/database"
"github.com/pgEdge/control-plane/server/internal/database/operations"
"github.com/pgEdge/control-plane/server/internal/monitor"
"github.com/pgEdge/control-plane/server/internal/resource"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -176,3 +177,152 @@ func (r *restoreResource) Identifier() resource.Identifier {
Type: "orchestrator.restore_resource",
}
}

// Service resource stubs using the orchestratorResource embedding pattern.
// These mirror the real resource types' Identifier/Dependencies/DiffIgnore
// without importing the swarm package.

type serviceNetworkResource struct {
orchestratorResource
nodeNames []string
}

func (r *serviceNetworkResource) Identifier() resource.Identifier {
return resource.Identifier{ID: r.ID, Type: "swarm.network"}
}

func (r *serviceNetworkResource) DiffIgnore() []string {
return []string{"/network_id", "/subnet", "/gateway"}
}

func (r *serviceNetworkResource) Executor() resource.Executor {
return resource.ManagerExecutor()
}

func (r *serviceNetworkResource) Dependencies() []resource.Identifier {
var deps []resource.Identifier
for _, name := range r.nodeNames {
deps = append(deps, database.NodeResourceIdentifier(name))
}
return deps
}

type serviceUserRoleResource struct {
orchestratorResource
nodeNames []string
}

func (r *serviceUserRoleResource) Identifier() resource.Identifier {
return resource.Identifier{ID: r.ID, Type: "swarm.service_user_role"}
}

func (r *serviceUserRoleResource) DiffIgnore() []string {
return []string{"/postgres_host_id", "/username", "/password"}
}

func (r *serviceUserRoleResource) Dependencies() []resource.Identifier {
var deps []resource.Identifier
for _, name := range r.nodeNames {
deps = append(deps, database.NodeResourceIdentifier(name))
}
return deps
}

type serviceInstanceSpecResource struct {
orchestratorResource
networkID string
serviceInstanceID string
hostID string
}

func (r *serviceInstanceSpecResource) Executor() resource.Executor {
return resource.HostExecutor(r.hostID)
}

func (r *serviceInstanceSpecResource) Identifier() resource.Identifier {
return resource.Identifier{ID: r.ID, Type: "swarm.service_instance_spec"}
}

func (r *serviceInstanceSpecResource) DiffIgnore() []string {
return []string{"/spec"}
}

func (r *serviceInstanceSpecResource) Dependencies() []resource.Identifier {
return []resource.Identifier{
{ID: r.networkID, Type: "swarm.network"},
{ID: r.serviceInstanceID, Type: "swarm.service_user_role"},
}
}

type serviceInstanceResource struct {
orchestratorResource
serviceInstanceID string
}

func (r *serviceInstanceResource) Identifier() resource.Identifier {
return resource.Identifier{ID: r.ID, Type: "swarm.service_instance"}
}

func (r *serviceInstanceResource) DiffIgnore() []string {
return []string{"/database_id", "/service_id", "/host_id"}
}

func (r *serviceInstanceResource) Executor() resource.Executor {
return resource.ManagerExecutor()
}

func (r *serviceInstanceResource) Dependencies() []resource.Identifier {
return []resource.Identifier{
{ID: r.serviceInstanceID, Type: "swarm.service_user_role"},
{ID: r.serviceInstanceID, Type: "swarm.service_instance_spec"},
}
}

func makeServiceResources(t testing.TB, databaseID, serviceID, hostID string, nodeNames []string) *operations.ServiceResources {
t.Helper()

serviceInstanceID := database.GenerateServiceInstanceID(databaseID, serviceID, hostID)
databaseNetworkID := database.GenerateDatabaseNetworkID(databaseID)

resources := []resource.Resource{
&serviceNetworkResource{
orchestratorResource: orchestratorResource{ID: databaseNetworkID},
nodeNames: nodeNames,
},
&serviceUserRoleResource{
orchestratorResource: orchestratorResource{ID: serviceInstanceID},
nodeNames: nodeNames,
},
&serviceInstanceSpecResource{
orchestratorResource: orchestratorResource{ID: serviceInstanceID},
networkID: databaseNetworkID,
serviceInstanceID: serviceInstanceID,
hostID: hostID,
},
&serviceInstanceResource{
orchestratorResource: orchestratorResource{ID: serviceInstanceID},
serviceInstanceID: serviceInstanceID,
},
}

resourceData := make([]*resource.ResourceData, len(resources))
for i, res := range resources {
rd, err := resource.ToResourceData(res)
if err != nil {
t.Fatal(err)
}
resourceData[i] = rd
}

monitorResource := &monitor.ServiceInstanceMonitorResource{
DatabaseID: databaseID,
ServiceInstanceID: serviceInstanceID,
HostID: hostID,
}

return &operations.ServiceResources{
ServiceInstanceID: serviceInstanceID,
Resources: resourceData,
MonitorResource: monitorResource,
}
}
Loading