This is an automated email from the ASF dual-hosted git repository. lahirujayathilake pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit e9b956bdb7a2fc282a20d663acedb4e325fb6c88 Author: lahiruj <[email protected]> AuthorDate: Fri Apr 17 10:49:11 2026 -0400 Extract shared domain models for the allocation management --- allocations/access-amie/go.mod | 8 ++- .../access-amie/handler/request_account_create.go | 9 ++-- .../handler/request_account_create_test.go | 25 ++++----- .../access-amie/handler/request_project_create.go | 9 ++-- .../handler/request_project_create_test.go | 25 ++++----- allocations/access-amie/main.go | 11 ++-- allocations/access-amie/service/account_service.go | 2 +- .../access-amie/service/account_service_test.go | 2 +- .../access-amie/service/membership_service.go | 2 +- .../access-amie/service/membership_service_test.go | 2 +- allocations/access-amie/service/person_service.go | 2 +- .../access-amie/service/person_service_test.go | 2 +- allocations/access-amie/service/project_service.go | 2 +- .../access-amie/service/project_service_test.go | 2 +- allocations/domain/go.mod | 5 ++ .../model/cluster_account.go | 1 - .../{access-amie => domain}/model/membership.go | 1 - .../{access-amie => domain}/model/person.go | 2 - .../{access-amie => domain}/model/project.go | 1 - .../{access-amie => domain}/store/account_store.go | 9 +--- .../store/membership_store.go | 11 +--- .../store/person_dns_store.go | 11 +--- .../{access-amie => domain}/store/person_store.go | 9 +--- .../{access-amie => domain}/store/project_store.go | 8 +-- allocations/domain/store/stores.go | 62 ++++++++++++++++++++++ allocations/go.work | 1 + 26 files changed, 129 insertions(+), 95 deletions(-) diff --git a/allocations/access-amie/go.mod b/allocations/access-amie/go.mod index 1a4ab0bca..411faa376 100644 --- a/allocations/access-amie/go.mod +++ b/allocations/access-amie/go.mod @@ -3,11 +3,13 @@ module github.com/apache/airavata-custos/allocations/access-amie go 1.22.0 require ( + github.com/apache/airavata-custos/allocations/domain v0.0.0 github.com/go-sql-driver/mysql v1.8.1 github.com/golang-migrate/migrate/v4 v4.18.1 github.com/google/uuid v1.6.0 github.com/jmoiron/sqlx v1.4.0 github.com/prometheus/client_golang v1.20.5 + github.com/prometheus/client_model v0.6.1 github.com/stretchr/testify v1.10.0 google.golang.org/protobuf v1.36.4 gopkg.in/yaml.v3 v3.0.1 @@ -23,7 +25,6 @@ require ( github.com/klauspost/compress v1.17.9 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.55.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/stretchr/objx v0.5.2 // indirect @@ -31,4 +32,7 @@ require ( golang.org/x/sys v0.25.0 // indirect ) -replace github.com/apache/airavata-custos/allocations/provisioner => ../provisioner +replace ( + github.com/apache/airavata-custos/allocations/domain => ../domain + github.com/apache/airavata-custos/allocations/provisioner => ../provisioner +) diff --git a/allocations/access-amie/handler/request_account_create.go b/allocations/access-amie/handler/request_account_create.go index 1fcc8a839..dc16fcab2 100644 --- a/allocations/access-amie/handler/request_account_create.go +++ b/allocations/access-amie/handler/request_account_create.go @@ -23,22 +23,23 @@ import ( "fmt" "github.com/apache/airavata-custos/allocations/access-amie/model" + dmodel "github.com/apache/airavata-custos/allocations/domain/model" ) type requestAccountCreatePersonService interface { - FindOrCreateFromPacket(ctx context.Context, tx *sql.Tx, body map[string]any) (*model.Person, error) + FindOrCreateFromPacket(ctx context.Context, tx *sql.Tx, body map[string]any) (*dmodel.Person, error) } type requestAccountCreateAccountService interface { - ProvisionClusterAccount(ctx context.Context, tx *sql.Tx, person *model.Person) (*model.ClusterAccount, error) + ProvisionClusterAccount(ctx context.Context, tx *sql.Tx, person *dmodel.Person) (*dmodel.ClusterAccount, error) } type requestAccountCreateProjectService interface { - CreateOrFindProject(ctx context.Context, tx *sql.Tx, projectID, grantNumber string) (*model.Project, error) + CreateOrFindProject(ctx context.Context, tx *sql.Tx, projectID, grantNumber string) (*dmodel.Project, error) } type requestAccountCreateMembershipService interface { - CreateMembership(ctx context.Context, tx *sql.Tx, projectID, clusterAccountID, role string) (*model.ProjectMembership, error) + CreateMembership(ctx context.Context, tx *sql.Tx, projectID, clusterAccountID, role string) (*dmodel.ProjectMembership, error) } type requestAccountCreateAmieClient interface { diff --git a/allocations/access-amie/handler/request_account_create_test.go b/allocations/access-amie/handler/request_account_create_test.go index 5411e650d..acbc7d858 100644 --- a/allocations/access-amie/handler/request_account_create_test.go +++ b/allocations/access-amie/handler/request_account_create_test.go @@ -23,6 +23,7 @@ import ( "testing" "github.com/apache/airavata-custos/allocations/access-amie/model" + dmodel "github.com/apache/airavata-custos/allocations/domain/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -34,42 +35,42 @@ import ( type mockRACPersonService struct{ mock.Mock } -func (m *mockRACPersonService) FindOrCreateFromPacket(ctx context.Context, tx *sql.Tx, body map[string]any) (*model.Person, error) { +func (m *mockRACPersonService) FindOrCreateFromPacket(ctx context.Context, tx *sql.Tx, body map[string]any) (*dmodel.Person, error) { args := m.Called(ctx, tx, body) if args.Get(0) == nil { return nil, args.Error(1) } - return args.Get(0).(*model.Person), args.Error(1) + return args.Get(0).(*dmodel.Person), args.Error(1) } type mockRACAccountService struct{ mock.Mock } -func (m *mockRACAccountService) ProvisionClusterAccount(ctx context.Context, tx *sql.Tx, person *model.Person) (*model.ClusterAccount, error) { +func (m *mockRACAccountService) ProvisionClusterAccount(ctx context.Context, tx *sql.Tx, person *dmodel.Person) (*dmodel.ClusterAccount, error) { args := m.Called(ctx, tx, person) if args.Get(0) == nil { return nil, args.Error(1) } - return args.Get(0).(*model.ClusterAccount), args.Error(1) + return args.Get(0).(*dmodel.ClusterAccount), args.Error(1) } type mockRACProjectService struct{ mock.Mock } -func (m *mockRACProjectService) CreateOrFindProject(ctx context.Context, tx *sql.Tx, projectID, grantNumber string) (*model.Project, error) { +func (m *mockRACProjectService) CreateOrFindProject(ctx context.Context, tx *sql.Tx, projectID, grantNumber string) (*dmodel.Project, error) { args := m.Called(ctx, tx, projectID, grantNumber) if args.Get(0) == nil { return nil, args.Error(1) } - return args.Get(0).(*model.Project), args.Error(1) + return args.Get(0).(*dmodel.Project), args.Error(1) } type mockRACMembershipService struct{ mock.Mock } -func (m *mockRACMembershipService) CreateMembership(ctx context.Context, tx *sql.Tx, projectID, clusterAccountID, role string) (*model.ProjectMembership, error) { +func (m *mockRACMembershipService) CreateMembership(ctx context.Context, tx *sql.Tx, projectID, clusterAccountID, role string) (*dmodel.ProjectMembership, error) { args := m.Called(ctx, tx, projectID, clusterAccountID, role) if args.Get(0) == nil { return nil, args.Error(1) } - return args.Get(0).(*model.ProjectMembership), args.Error(1) + return args.Get(0).(*dmodel.ProjectMembership), args.Error(1) } type mockRACAmieClient struct{ mock.Mock } @@ -110,9 +111,9 @@ func TestRequestAccountCreateHandler(t *testing.T) { name: "valid packet processes successfully", input: validFixture, setupMocks: func(ps *mockRACPersonService, as *mockRACAccountService, prj *mockRACProjectService, ms *mockRACMembershipService, ac *mockRACAmieClient, aud *mockRACAuditService) { - person := &model.Person{ID: "person-123"} - account := &model.ClusterAccount{ID: "account-123", Username: "testuser"} - project := &model.Project{ID: "test-project-456", GrantNumber: "TEST123"} + person := &dmodel.Person{ID: "person-123"} + account := &dmodel.ClusterAccount{ID: "account-123", Username: "testuser"} + project := &dmodel.Project{ID: "test-project-456", GrantNumber: "TEST123"} ps.On("FindOrCreateFromPacket", mock.Anything, mock.Anything, mock.Anything).Return(person, nil) aud.On("Log", mock.Anything, mock.Anything, mock.Anything, mock.Anything, model.AuditCreatePerson, mock.Anything, mock.Anything, mock.Anything).Return(nil) @@ -122,7 +123,7 @@ func TestRequestAccountCreateHandler(t *testing.T) { prj.On("CreateOrFindProject", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(project, nil) - ms.On("CreateMembership", mock.Anything, mock.Anything, "test-project-456", account.ID, "USER").Return(&model.ProjectMembership{}, nil) + ms.On("CreateMembership", mock.Anything, mock.Anything, "test-project-456", account.ID, "USER").Return(&dmodel.ProjectMembership{}, nil) aud.On("Log", mock.Anything, mock.Anything, mock.Anything, mock.Anything, model.AuditCreateMembership, mock.Anything, mock.Anything, mock.Anything).Return(nil) ac.On("ReplyToPacket", mock.Anything, int64(233497917), mock.Anything).Return(nil) diff --git a/allocations/access-amie/handler/request_project_create.go b/allocations/access-amie/handler/request_project_create.go index 01c9cba34..d8a42595b 100644 --- a/allocations/access-amie/handler/request_project_create.go +++ b/allocations/access-amie/handler/request_project_create.go @@ -23,22 +23,23 @@ import ( "fmt" "github.com/apache/airavata-custos/allocations/access-amie/model" + dmodel "github.com/apache/airavata-custos/allocations/domain/model" ) type requestProjectCreatePersonService interface { - FindOrCreateFromPacket(ctx context.Context, tx *sql.Tx, body map[string]any) (*model.Person, error) + FindOrCreateFromPacket(ctx context.Context, tx *sql.Tx, body map[string]any) (*dmodel.Person, error) } type requestProjectCreateAccountService interface { - ProvisionClusterAccount(ctx context.Context, tx *sql.Tx, person *model.Person) (*model.ClusterAccount, error) + ProvisionClusterAccount(ctx context.Context, tx *sql.Tx, person *dmodel.Person) (*dmodel.ClusterAccount, error) } type requestProjectCreateProjectService interface { - CreateOrFindProject(ctx context.Context, tx *sql.Tx, projectID, grantNumber string) (*model.Project, error) + CreateOrFindProject(ctx context.Context, tx *sql.Tx, projectID, grantNumber string) (*dmodel.Project, error) } type requestProjectCreateMembershipService interface { - CreateMembership(ctx context.Context, tx *sql.Tx, projectID, clusterAccountID, role string) (*model.ProjectMembership, error) + CreateMembership(ctx context.Context, tx *sql.Tx, projectID, clusterAccountID, role string) (*dmodel.ProjectMembership, error) } type requestProjectCreateAmieClient interface { diff --git a/allocations/access-amie/handler/request_project_create_test.go b/allocations/access-amie/handler/request_project_create_test.go index d3749da94..72114f339 100644 --- a/allocations/access-amie/handler/request_project_create_test.go +++ b/allocations/access-amie/handler/request_project_create_test.go @@ -23,6 +23,7 @@ import ( "testing" "github.com/apache/airavata-custos/allocations/access-amie/model" + dmodel "github.com/apache/airavata-custos/allocations/domain/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -34,42 +35,42 @@ import ( type mockRPCPersonService struct{ mock.Mock } -func (m *mockRPCPersonService) FindOrCreateFromPacket(ctx context.Context, tx *sql.Tx, body map[string]any) (*model.Person, error) { +func (m *mockRPCPersonService) FindOrCreateFromPacket(ctx context.Context, tx *sql.Tx, body map[string]any) (*dmodel.Person, error) { args := m.Called(ctx, tx, body) if args.Get(0) == nil { return nil, args.Error(1) } - return args.Get(0).(*model.Person), args.Error(1) + return args.Get(0).(*dmodel.Person), args.Error(1) } type mockRPCAccountService struct{ mock.Mock } -func (m *mockRPCAccountService) ProvisionClusterAccount(ctx context.Context, tx *sql.Tx, person *model.Person) (*model.ClusterAccount, error) { +func (m *mockRPCAccountService) ProvisionClusterAccount(ctx context.Context, tx *sql.Tx, person *dmodel.Person) (*dmodel.ClusterAccount, error) { args := m.Called(ctx, tx, person) if args.Get(0) == nil { return nil, args.Error(1) } - return args.Get(0).(*model.ClusterAccount), args.Error(1) + return args.Get(0).(*dmodel.ClusterAccount), args.Error(1) } type mockRPCProjectService struct{ mock.Mock } -func (m *mockRPCProjectService) CreateOrFindProject(ctx context.Context, tx *sql.Tx, projectID, grantNumber string) (*model.Project, error) { +func (m *mockRPCProjectService) CreateOrFindProject(ctx context.Context, tx *sql.Tx, projectID, grantNumber string) (*dmodel.Project, error) { args := m.Called(ctx, tx, projectID, grantNumber) if args.Get(0) == nil { return nil, args.Error(1) } - return args.Get(0).(*model.Project), args.Error(1) + return args.Get(0).(*dmodel.Project), args.Error(1) } type mockRPCMembershipService struct{ mock.Mock } -func (m *mockRPCMembershipService) CreateMembership(ctx context.Context, tx *sql.Tx, projectID, clusterAccountID, role string) (*model.ProjectMembership, error) { +func (m *mockRPCMembershipService) CreateMembership(ctx context.Context, tx *sql.Tx, projectID, clusterAccountID, role string) (*dmodel.ProjectMembership, error) { args := m.Called(ctx, tx, projectID, clusterAccountID, role) if args.Get(0) == nil { return nil, args.Error(1) } - return args.Get(0).(*model.ProjectMembership), args.Error(1) + return args.Get(0).(*dmodel.ProjectMembership), args.Error(1) } type mockRPCAmieClient struct{ mock.Mock } @@ -125,9 +126,9 @@ func TestRequestProjectCreateHandler(t *testing.T) { name: "valid packet processes successfully", input: validFixture, setupMocks: func(ps *mockRPCPersonService, as *mockRPCAccountService, prj *mockRPCProjectService, ms *mockRPCMembershipService, ac *mockRPCAmieClient, aud *mockRPCAuditService) { - person := &model.Person{ID: "person-123"} - account := &model.ClusterAccount{ID: "account-123", Username: "hwan"} - project := &model.Project{ID: "project-123", GrantNumber: "NNT259276"} + person := &dmodel.Person{ID: "person-123"} + account := &dmodel.ClusterAccount{ID: "account-123", Username: "hwan"} + project := &dmodel.Project{ID: "project-123", GrantNumber: "NNT259276"} ps.On("FindOrCreateFromPacket", mock.Anything, mock.Anything, mock.Anything).Return(person, nil) aud.On("Log", mock.Anything, mock.Anything, mock.Anything, mock.Anything, model.AuditCreatePerson, mock.Anything, mock.Anything, mock.Anything).Return(nil) @@ -138,7 +139,7 @@ func TestRequestProjectCreateHandler(t *testing.T) { prj.On("CreateOrFindProject", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(project, nil) aud.On("Log", mock.Anything, mock.Anything, mock.Anything, mock.Anything, model.AuditCreateProject, mock.Anything, mock.Anything, mock.Anything).Return(nil) - ms.On("CreateMembership", mock.Anything, mock.Anything, project.ID, account.ID, "PI").Return(&model.ProjectMembership{}, nil) + ms.On("CreateMembership", mock.Anything, mock.Anything, project.ID, account.ID, "PI").Return(&dmodel.ProjectMembership{}, nil) aud.On("Log", mock.Anything, mock.Anything, mock.Anything, mock.Anything, model.AuditCreateMembership, mock.Anything, mock.Anything, mock.Anything).Return(nil) ac.On("ReplyToPacket", mock.Anything, int64(233497907), mock.Anything).Return(nil) diff --git a/allocations/access-amie/main.go b/allocations/access-amie/main.go index 64faf991f..77e78b424 100644 --- a/allocations/access-amie/main.go +++ b/allocations/access-amie/main.go @@ -33,6 +33,7 @@ import ( "github.com/apache/airavata-custos/allocations/access-amie/service" "github.com/apache/airavata-custos/allocations/access-amie/store" "github.com/apache/airavata-custos/allocations/access-amie/worker" + domainstore "github.com/apache/airavata-custos/allocations/domain/store" ) func main() { @@ -58,11 +59,11 @@ func main() { os.Exit(1) } - personStore := store.NewPersonStore(database) - personDNStore := store.NewPersonDNStore(database) - accountStore := store.NewClusterAccountStore(database) - projectStore := store.NewProjectStore(database) - membershipStore := store.NewMembershipStore(database) + personStore := domainstore.NewPersonStore(database) + personDNStore := domainstore.NewPersonDNStore(database) + accountStore := domainstore.NewClusterAccountStore(database) + projectStore := domainstore.NewProjectStore(database) + membershipStore := domainstore.NewMembershipStore(database) packetStore := store.NewPacketStore(database) eventStore := store.NewEventStore(database) errorStore := store.NewProcessingErrorStore(database) diff --git a/allocations/access-amie/service/account_service.go b/allocations/access-amie/service/account_service.go index f13631763..632fb224c 100644 --- a/allocations/access-amie/service/account_service.go +++ b/allocations/access-amie/service/account_service.go @@ -24,7 +24,7 @@ import ( "log/slog" "strings" - "github.com/apache/airavata-custos/allocations/access-amie/model" + "github.com/apache/airavata-custos/allocations/domain/model" "github.com/google/uuid" ) diff --git a/allocations/access-amie/service/account_service_test.go b/allocations/access-amie/service/account_service_test.go index 3cdcea7c2..498becddd 100644 --- a/allocations/access-amie/service/account_service_test.go +++ b/allocations/access-amie/service/account_service_test.go @@ -22,7 +22,7 @@ import ( "database/sql" "testing" - "github.com/apache/airavata-custos/allocations/access-amie/model" + "github.com/apache/airavata-custos/allocations/domain/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" diff --git a/allocations/access-amie/service/membership_service.go b/allocations/access-amie/service/membership_service.go index a03c241d4..119107b53 100644 --- a/allocations/access-amie/service/membership_service.go +++ b/allocations/access-amie/service/membership_service.go @@ -23,7 +23,7 @@ import ( "fmt" "log/slog" - "github.com/apache/airavata-custos/allocations/access-amie/model" + "github.com/apache/airavata-custos/allocations/domain/model" "github.com/google/uuid" ) diff --git a/allocations/access-amie/service/membership_service_test.go b/allocations/access-amie/service/membership_service_test.go index e9e0e7a6b..4298ef08d 100644 --- a/allocations/access-amie/service/membership_service_test.go +++ b/allocations/access-amie/service/membership_service_test.go @@ -22,7 +22,7 @@ import ( "database/sql" "testing" - "github.com/apache/airavata-custos/allocations/access-amie/model" + "github.com/apache/airavata-custos/allocations/domain/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" diff --git a/allocations/access-amie/service/person_service.go b/allocations/access-amie/service/person_service.go index f4654ce23..ea9391b9d 100644 --- a/allocations/access-amie/service/person_service.go +++ b/allocations/access-amie/service/person_service.go @@ -23,7 +23,7 @@ import ( "fmt" "log/slog" - "github.com/apache/airavata-custos/allocations/access-amie/model" + "github.com/apache/airavata-custos/allocations/domain/model" "github.com/google/uuid" ) diff --git a/allocations/access-amie/service/person_service_test.go b/allocations/access-amie/service/person_service_test.go index b2c1809da..621682579 100644 --- a/allocations/access-amie/service/person_service_test.go +++ b/allocations/access-amie/service/person_service_test.go @@ -23,7 +23,7 @@ import ( "errors" "testing" - "github.com/apache/airavata-custos/allocations/access-amie/model" + "github.com/apache/airavata-custos/allocations/domain/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" diff --git a/allocations/access-amie/service/project_service.go b/allocations/access-amie/service/project_service.go index 1a382eb6d..f21012aab 100644 --- a/allocations/access-amie/service/project_service.go +++ b/allocations/access-amie/service/project_service.go @@ -23,7 +23,7 @@ import ( "fmt" "log/slog" - "github.com/apache/airavata-custos/allocations/access-amie/model" + "github.com/apache/airavata-custos/allocations/domain/model" ) type projectStore interface { diff --git a/allocations/access-amie/service/project_service_test.go b/allocations/access-amie/service/project_service_test.go index 22d2a5c3b..f5db8438a 100644 --- a/allocations/access-amie/service/project_service_test.go +++ b/allocations/access-amie/service/project_service_test.go @@ -22,7 +22,7 @@ import ( "database/sql" "testing" - "github.com/apache/airavata-custos/allocations/access-amie/model" + "github.com/apache/airavata-custos/allocations/domain/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" diff --git a/allocations/domain/go.mod b/allocations/domain/go.mod new file mode 100644 index 000000000..6a5850e22 --- /dev/null +++ b/allocations/domain/go.mod @@ -0,0 +1,5 @@ +module github.com/apache/airavata-custos/allocations/domain + +go 1.22.0 + +require github.com/jmoiron/sqlx v1.4.0 diff --git a/allocations/access-amie/model/cluster_account.go b/allocations/domain/model/cluster_account.go similarity index 93% rename from allocations/access-amie/model/cluster_account.go rename to allocations/domain/model/cluster_account.go index 0ae530b11..015645cb5 100644 --- a/allocations/access-amie/model/cluster_account.go +++ b/allocations/domain/model/cluster_account.go @@ -19,7 +19,6 @@ package model import "time" -// ClusterAccount maps a person to their username on a target HPC cluster. type ClusterAccount struct { ID string `db:"id" json:"id"` PersonID string `db:"person_id" json:"person_id"` diff --git a/allocations/access-amie/model/membership.go b/allocations/domain/model/membership.go similarity index 94% rename from allocations/access-amie/model/membership.go rename to allocations/domain/model/membership.go index 327db2f09..c9b080c0a 100644 --- a/allocations/access-amie/model/membership.go +++ b/allocations/domain/model/membership.go @@ -19,7 +19,6 @@ package model import "time" -// ProjectMembership links a cluster account to a project with an optional role. type ProjectMembership struct { ID string `db:"id" json:"id"` ProjectID string `db:"project_id" json:"project_id"` diff --git a/allocations/access-amie/model/person.go b/allocations/domain/model/person.go similarity index 92% rename from allocations/access-amie/model/person.go rename to allocations/domain/model/person.go index fd1916ec9..1b1b65382 100644 --- a/allocations/access-amie/model/person.go +++ b/allocations/domain/model/person.go @@ -19,7 +19,6 @@ package model import "time" -// Person represents a researcher or PI known to the AMIE system. type Person struct { ID string `db:"id" json:"id"` AccessGlobalID string `db:"access_global_id" json:"access_global_id"` @@ -33,7 +32,6 @@ type Person struct { UpdatedAt time.Time `db:"updated_at" json:"updated_at"` } -// PersonDN holds a single Distinguished Name associated with a person. type PersonDN struct { ID int64 `db:"id" json:"id"` PersonID string `db:"person_id" json:"person_id"` diff --git a/allocations/access-amie/model/project.go b/allocations/domain/model/project.go similarity index 94% rename from allocations/access-amie/model/project.go rename to allocations/domain/model/project.go index e61a8667b..68af3147a 100644 --- a/allocations/access-amie/model/project.go +++ b/allocations/domain/model/project.go @@ -19,7 +19,6 @@ package model import "time" -// Project represents an allocation grant tracked by the AMIE system. type Project struct { ID string `db:"id" json:"id"` GrantNumber string `db:"grant_number" json:"grant_number"` diff --git a/allocations/access-amie/store/account_store.go b/allocations/domain/store/account_store.go similarity index 84% rename from allocations/access-amie/store/account_store.go rename to allocations/domain/store/account_store.go index 9221da46e..beecc5b79 100644 --- a/allocations/access-amie/store/account_store.go +++ b/allocations/domain/store/account_store.go @@ -22,17 +22,10 @@ import ( "database/sql" "errors" - "github.com/apache/airavata-custos/allocations/access-amie/model" + "github.com/apache/airavata-custos/allocations/domain/model" "github.com/jmoiron/sqlx" ) -type ClusterAccountStore interface { - FindByUsername(ctx context.Context, username string) (*model.ClusterAccount, error) - FindByPerson(ctx context.Context, personID string) ([]model.ClusterAccount, error) - Save(ctx context.Context, tx *sql.Tx, a *model.ClusterAccount) error - UpdatePersonID(ctx context.Context, tx *sql.Tx, accountID, newPersonID string) error -} - type mariaDBClusterAccountStore struct { db *sqlx.DB } diff --git a/allocations/access-amie/store/membership_store.go b/allocations/domain/store/membership_store.go similarity index 84% rename from allocations/access-amie/store/membership_store.go rename to allocations/domain/store/membership_store.go index 24cbd0acf..bbf19ab43 100644 --- a/allocations/access-amie/store/membership_store.go +++ b/allocations/domain/store/membership_store.go @@ -22,19 +22,10 @@ import ( "database/sql" "errors" - "github.com/apache/airavata-custos/allocations/access-amie/model" + "github.com/apache/airavata-custos/allocations/domain/model" "github.com/jmoiron/sqlx" ) -type MembershipStore interface { - FindByProjectAndAccount(ctx context.Context, projectID, accountID string) (*model.ProjectMembership, error) - FindByProject(ctx context.Context, projectID string) ([]model.ProjectMembership, error) - FindByProjectAndRole(ctx context.Context, projectID, role string) ([]model.ProjectMembership, error) - FindByProjectAndPerson(ctx context.Context, projectID, personID string) ([]model.ProjectMembership, error) - Save(ctx context.Context, tx *sql.Tx, m *model.ProjectMembership) error - Update(ctx context.Context, tx *sql.Tx, m *model.ProjectMembership) error -} - type mariaDBMembershipStore struct { db *sqlx.DB } diff --git a/allocations/access-amie/store/person_dns_store.go b/allocations/domain/store/person_dns_store.go similarity index 81% rename from allocations/access-amie/store/person_dns_store.go rename to allocations/domain/store/person_dns_store.go index 531a541c5..b1d246d08 100644 --- a/allocations/access-amie/store/person_dns_store.go +++ b/allocations/domain/store/person_dns_store.go @@ -21,18 +21,10 @@ import ( "context" "database/sql" - "github.com/apache/airavata-custos/allocations/access-amie/model" + "github.com/apache/airavata-custos/allocations/domain/model" "github.com/jmoiron/sqlx" ) -type PersonDNStore interface { - ExistsByPersonAndDN(ctx context.Context, personID, dn string) (bool, error) - Save(ctx context.Context, tx *sql.Tx, d *model.PersonDN) error - DeleteByPersonID(ctx context.Context, tx *sql.Tx, personID string) error - DeleteByPersonIDNotIn(ctx context.Context, tx *sql.Tx, personID string, dnsToKeep []string) error - FindByPersonID(ctx context.Context, personID string) ([]model.PersonDN, error) -} - type mariaDBPersonDNStore struct { db *sqlx.DB } @@ -66,7 +58,6 @@ func (s *mariaDBPersonDNStore) DeleteByPersonID(ctx context.Context, tx *sql.Tx, func (s *mariaDBPersonDNStore) DeleteByPersonIDNotIn(ctx context.Context, tx *sql.Tx, personID string, dnsToKeep []string) error { if len(dnsToKeep) == 0 { - // Nothing to keep means delete all for this person. return s.DeleteByPersonID(ctx, tx, personID) } query, args, err := sqlx.In( diff --git a/allocations/access-amie/store/person_store.go b/allocations/domain/store/person_store.go similarity index 87% rename from allocations/access-amie/store/person_store.go rename to allocations/domain/store/person_store.go index f2ad6fbee..00122edf5 100644 --- a/allocations/access-amie/store/person_store.go +++ b/allocations/domain/store/person_store.go @@ -22,17 +22,10 @@ import ( "database/sql" "errors" - "github.com/apache/airavata-custos/allocations/access-amie/model" + "github.com/apache/airavata-custos/allocations/domain/model" "github.com/jmoiron/sqlx" ) -type PersonStore interface { - FindByID(ctx context.Context, id string) (*model.Person, error) - FindByAccessGlobalID(ctx context.Context, globalID string) (*model.Person, error) - Save(ctx context.Context, tx *sql.Tx, p *model.Person) error - Delete(ctx context.Context, tx *sql.Tx, id string) error -} - type mariaDBPersonStore struct { db *sqlx.DB } diff --git a/allocations/access-amie/store/project_store.go b/allocations/domain/store/project_store.go similarity index 87% rename from allocations/access-amie/store/project_store.go rename to allocations/domain/store/project_store.go index 8066a8546..758c7de89 100644 --- a/allocations/access-amie/store/project_store.go +++ b/allocations/domain/store/project_store.go @@ -22,16 +22,10 @@ import ( "database/sql" "errors" - "github.com/apache/airavata-custos/allocations/access-amie/model" + "github.com/apache/airavata-custos/allocations/domain/model" "github.com/jmoiron/sqlx" ) -type ProjectStore interface { - FindByID(ctx context.Context, id string) (*model.Project, error) - Save(ctx context.Context, tx *sql.Tx, p *model.Project) error - Update(ctx context.Context, tx *sql.Tx, p *model.Project) error -} - type mariaDBProjectStore struct { db *sqlx.DB } diff --git a/allocations/domain/store/stores.go b/allocations/domain/store/stores.go new file mode 100644 index 000000000..786119497 --- /dev/null +++ b/allocations/domain/store/stores.go @@ -0,0 +1,62 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package store + +import ( + "context" + "database/sql" + + "github.com/apache/airavata-custos/allocations/domain/model" +) + +type PersonStore interface { + FindByID(ctx context.Context, id string) (*model.Person, error) + FindByAccessGlobalID(ctx context.Context, globalID string) (*model.Person, error) + Save(ctx context.Context, tx *sql.Tx, p *model.Person) error + Delete(ctx context.Context, tx *sql.Tx, id string) error +} + +type PersonDNStore interface { + ExistsByPersonAndDN(ctx context.Context, personID, dn string) (bool, error) + Save(ctx context.Context, tx *sql.Tx, d *model.PersonDN) error + DeleteByPersonID(ctx context.Context, tx *sql.Tx, personID string) error + DeleteByPersonIDNotIn(ctx context.Context, tx *sql.Tx, personID string, dnsToKeep []string) error + FindByPersonID(ctx context.Context, personID string) ([]model.PersonDN, error) +} + +type ClusterAccountStore interface { + FindByUsername(ctx context.Context, username string) (*model.ClusterAccount, error) + FindByPerson(ctx context.Context, personID string) ([]model.ClusterAccount, error) + Save(ctx context.Context, tx *sql.Tx, a *model.ClusterAccount) error + UpdatePersonID(ctx context.Context, tx *sql.Tx, accountID, newPersonID string) error +} + +type ProjectStore interface { + FindByID(ctx context.Context, id string) (*model.Project, error) + Save(ctx context.Context, tx *sql.Tx, p *model.Project) error + Update(ctx context.Context, tx *sql.Tx, p *model.Project) error +} + +type MembershipStore interface { + FindByProjectAndAccount(ctx context.Context, projectID, accountID string) (*model.ProjectMembership, error) + FindByProject(ctx context.Context, projectID string) ([]model.ProjectMembership, error) + FindByProjectAndRole(ctx context.Context, projectID, role string) ([]model.ProjectMembership, error) + FindByProjectAndPerson(ctx context.Context, projectID, personID string) ([]model.ProjectMembership, error) + Save(ctx context.Context, tx *sql.Tx, m *model.ProjectMembership) error + Update(ctx context.Context, tx *sql.Tx, m *model.ProjectMembership) error +} diff --git a/allocations/go.work b/allocations/go.work index ac830f1e7..2d21981a9 100644 --- a/allocations/go.work +++ b/allocations/go.work @@ -1,6 +1,7 @@ go 1.22.0 use ( + ./domain ./provisioner ./access-amie )
