You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by la...@apache.org on 2026/06/16 06:56:45 UTC
(airavata-custos) branch nexus-portal created (now d40d5338d)
This is an automated email from the ASF dual-hosted git repository.
lahirujayathilake pushed a change to branch nexus-portal
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
at d40d5338d Add REST list endpoints, membership role + PI write on project create, AMIE responses, and connector idempotency fixes
This branch includes the following new commits:
new d40d5338d Add REST list endpoints, membership role + PI write on project create, AMIE responses, and connector idempotency fixes
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(airavata-custos) 01/01: Add REST list endpoints, membership role + PI write on project create, AMIE responses, and connector idempotency fixes
Posted by la...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lahirujayathilake pushed a commit to branch nexus-portal
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit d40d5338d0457665882bd1cfefb932a1045bd696
Author: lahiruj <la...@gmail.com>
AuthorDate: Tue Jun 16 02:56:34 2026 -0400
Add REST list endpoints, membership role + PI write on project create, AMIE responses, and connector idempotency fixes
---
api/core.openapi.yaml | 550 ++++++++++++++-------
cmd/server/main.go | 2 +-
config/custos.yaml | 24 +-
.../handler/request_account_create.go | 21 +-
.../handler/request_project_create.go | 39 ++
.../ACCESS/AMIE-Processor/pkg/amie/loader.go | 4 +-
.../ACCESS/AMIE-Processor/server/handlers.go | 211 +++++++-
.../ACCESS/AMIE-Processor/server/handlers_test.go | 4 +-
.../ACCESS/AMIE-Processor/server/responses.go | 190 +++++++
.../ACCESS/AMIE-Processor/store/packet_store.go | 122 ++++-
.../internal/client/client_test.go | 45 ++
.../internal/client/identifiers.go | 29 ++
.../internal/client/unix_cluster.go | 44 ++
.../internal/operations/ensure_posix_account.go | 108 +++-
.../internal/operations/orchestrator_test.go | 4 +-
dev-ops/compose/seeds/dev_portal_data.sql | 141 ++++++
dev-ops/local-amie/compose.yaml | 2 +-
.../db/migrations/000013_membership_role.down.sql | 20 +
.../db/migrations/000013_membership_role.up.sql | 23 +
internal/server/responses.go | 92 ++++
internal/server/server.go | 227 ++++++++-
.../compute_allocation_change_request_store.go | 24 +
.../store/compute_allocation_membership_store.go | 116 ++++-
internal/store/compute_allocation_store.go | 45 ++
internal/store/project_store.go | 124 +++++
internal/store/store.go | 47 ++
pkg/models/allocation.go | 1 +
pkg/posix/username_test.go | 10 +-
pkg/service/compute_allocation.go | 11 +
pkg/service/compute_allocation_change_request.go | 11 +
pkg/service/compute_allocation_membership.go | 35 +-
pkg/service/interface.go | 4 +-
pkg/service/mock.go | 57 ++-
pkg/service/project.go | 34 ++
34 files changed, 2163 insertions(+), 258 deletions(-)
diff --git a/api/core.openapi.yaml b/api/core.openapi.yaml
index e3334c3d2..7439096f0 100644
--- a/api/core.openapi.yaml
+++ b/api/core.openapi.yaml
@@ -1,6 +1,37 @@
basePath: /
definitions:
- models.AllocationStatus:
+ AllocationMembershipResponse:
+ properties:
+ compute_allocation_id:
+ type: string
+ display_name:
+ type: string
+ email:
+ type: string
+ end_time:
+ type: string
+ id:
+ type: string
+ membership_status:
+ allOf:
+ - $ref: '#/definitions/AllocationStatus'
+ description: ACTIVE, INACTIVE, etc.
+ role:
+ description: PI, CO_PI, ALLOCATION_MANAGER, MEMBER
+ type: string
+ start_time:
+ type: string
+ user_id:
+ type: string
+ type: object
+ AllocationSUTotalResponse:
+ properties:
+ compute_allocation_id:
+ type: string
+ total_su_amount:
+ type: integer
+ type: object
+ AllocationStatus:
enum:
- ACTIVE
- INACTIVE
@@ -10,7 +41,7 @@ definitions:
- ACTIVE
- INACTIVE
- DELETED
- models.ComputeAllocation:
+ ComputeAllocation:
properties:
compute_cluster_id:
description: The ID of the compute cluster where the allocation is provisioned.
@@ -30,10 +61,10 @@ definitions:
type: string
status:
allOf:
- - $ref: '#/definitions/models.AllocationStatus'
+ - $ref: '#/definitions/AllocationStatus'
description: ACTIVE, INACTIVE, DELETED, etc.
type: object
- models.ComputeAllocationChangeRequest:
+ ComputeAllocationChangeRequest:
properties:
approver_id:
description: The ID of the user who approved/rejected the change request,
@@ -52,7 +83,7 @@ definitions:
type: string
requested_status:
allOf:
- - $ref: '#/definitions/models.AllocationStatus'
+ - $ref: '#/definitions/AllocationStatus'
description: ACTIVE, INACTIVE, DELETED, etc.
requested_su_amount:
description: The requested allocation amount in SUs, e.g., 1200 SUs, etc.
@@ -64,7 +95,7 @@ definitions:
description: The time when the change request was made.
type: string
type: object
- models.ComputeAllocationChangeRequestEvent:
+ ComputeAllocationChangeRequestEvent:
properties:
compute_allocation_change_request_id:
type: string
@@ -81,7 +112,7 @@ definitions:
description: The time when the event occurred.
type: string
type: object
- models.ComputeAllocationDiff:
+ ComputeAllocationDiff:
properties:
compute_allocation_id:
type: string
@@ -100,13 +131,22 @@ definitions:
type: integer
status:
allOf:
- - $ref: '#/definitions/models.AllocationStatus'
+ - $ref: '#/definitions/AllocationStatus'
description: ACTIVE, INACTIVE, DELETED, etc.
timestamp:
description: The time when the diff was generated.
type: string
type: object
- models.ComputeAllocationMembership:
+ ComputeAllocationListResponse:
+ properties:
+ items:
+ items:
+ $ref: '#/definitions/ComputeAllocation'
+ type: array
+ total:
+ type: integer
+ type: object
+ ComputeAllocationMembership:
properties:
compute_allocation_id:
type: string
@@ -116,14 +156,17 @@ definitions:
type: string
membership_status:
allOf:
- - $ref: '#/definitions/models.AllocationStatus'
+ - $ref: '#/definitions/AllocationStatus'
description: ACTIVE, INACTIVE, etc.
+ role:
+ description: PI, CO_PI, ALLOCATION_MANAGER, MEMBER
+ type: string
start_time:
type: string
user_id:
type: string
type: object
- models.ComputeAllocationMembershipResourceOverride:
+ ComputeAllocationMembershipResourceOverride:
properties:
compute_allocation_membership_id:
type: string
@@ -140,7 +183,7 @@ definitions:
is granted for.
type: integer
type: object
- models.ComputeAllocationResource:
+ ComputeAllocationResource:
properties:
compute_cluster_id:
description: The ID of the compute cluster the resource (partition) belongs
@@ -159,7 +202,7 @@ definitions:
description: 'TRES: cpu, gres/gpu'
type: string
type: object
- models.ComputeAllocationResourceMapping:
+ ComputeAllocationResourceMapping:
properties:
compute_allocation_id:
type: string
@@ -176,7 +219,7 @@ definitions:
for.
type: integer
type: object
- models.ComputeAllocationResourceRate:
+ ComputeAllocationResourceRate:
properties:
compute_allocation_resource_id:
type: string
@@ -193,7 +236,7 @@ definitions:
description: The time when this rate becomes effective.
type: string
type: object
- models.ComputeAllocationUsage:
+ ComputeAllocationUsage:
properties:
compute_allocation_id:
type: string
@@ -222,7 +265,7 @@ definitions:
description: The ID of the user who used the allocation.
type: string
type: object
- models.ComputeCluster:
+ ComputeCluster:
properties:
id:
type: string
@@ -231,7 +274,7 @@ definitions:
A", "Cluster B", etc.
type: string
type: object
- models.ComputeClusterUser:
+ ComputeClusterUser:
properties:
compute_cluster_id:
type: string
@@ -244,7 +287,7 @@ definitions:
user_id:
type: string
type: object
- models.Organization:
+ Organization:
properties:
id:
type: string
@@ -255,7 +298,7 @@ definitions:
Record ID.'
type: string
type: object
- models.PrivilegeKey:
+ PrivilegeKey:
enum:
- amie:read
- amie:write
@@ -275,7 +318,7 @@ definitions:
- PrivilegeSignerWrite
- PrivilegeGrant
- PrivilegeRolesManage
- models.Project:
+ Project:
properties:
created_time:
type: string
@@ -291,11 +334,76 @@ definitions:
project_pi_id:
type: string
status:
- $ref: '#/definitions/models.ProjectStatus'
+ $ref: '#/definitions/ProjectStatus'
title:
type: string
type: object
- models.ProjectStatus:
+ ProjectListResponse:
+ properties:
+ items:
+ items:
+ $ref: '#/definitions/ProjectResponse'
+ type: array
+ total:
+ type: integer
+ type: object
+ ProjectMemberAllocationRef:
+ properties:
+ id:
+ type: string
+ name:
+ type: string
+ role:
+ type: string
+ type: object
+ ProjectMemberResponse:
+ properties:
+ added_time:
+ type: string
+ allocations:
+ items:
+ $ref: '#/definitions/ProjectMemberAllocationRef'
+ type: array
+ display_name:
+ type: string
+ email:
+ type: string
+ id:
+ type: string
+ project_id:
+ type: string
+ role:
+ type: string
+ status:
+ type: string
+ user_id:
+ type: string
+ type: object
+ ProjectResponse:
+ properties:
+ created_time:
+ type: string
+ id:
+ type: string
+ originated_id:
+ description: 'The ID of the project in origination. For example: ACCESS Record
+ ID.'
+ type: string
+ origination:
+ description: ACCESS, NAIRR, XRASS, etc.
+ type: string
+ project_pi_display_name:
+ type: string
+ project_pi_email:
+ type: string
+ project_pi_id:
+ type: string
+ status:
+ $ref: '#/definitions/ProjectStatus'
+ title:
+ type: string
+ type: object
+ ProjectStatus:
enum:
- ACTIVE
- INACTIVE
@@ -305,7 +413,7 @@ definitions:
- ProjectActive
- ProjectInactive
- ProjectDeleted
- models.Role:
+ Role:
properties:
created_at:
type: string
@@ -318,7 +426,7 @@ definitions:
name:
type: string
type: object
- models.TraceEvent:
+ TraceEvent:
properties:
created_at:
type: string
@@ -339,11 +447,11 @@ definitions:
status:
type: string
type: object
- models.TraceNode:
+ TraceNode:
properties:
children:
items:
- $ref: '#/definitions/models.TraceNode'
+ $ref: '#/definitions/TraceNode'
type: array
created_at:
type: string
@@ -364,7 +472,7 @@ definitions:
status:
type: string
type: object
- models.TraceSummary:
+ TraceSummary:
properties:
ended_at:
type: string
@@ -381,7 +489,7 @@ definitions:
trace_id:
type: string
type: object
- models.User:
+ User:
properties:
email:
type: string
@@ -396,9 +504,18 @@ definitions:
organization_id:
type: string
status:
- $ref: '#/definitions/models.UserStatus'
+ $ref: '#/definitions/UserStatus'
+ type: object
+ UserAllocationSUTotalResponse:
+ properties:
+ compute_allocation_id:
+ type: string
+ total_su_amount:
+ type: integer
+ user_id:
+ type: string
type: object
- models.UserIdentity:
+ UserIdentity:
properties:
created_at:
type: string
@@ -422,7 +539,7 @@ definitions:
user_id:
type: string
type: object
- models.UserPrivilege:
+ UserPrivilege:
properties:
granted_at:
type: string
@@ -431,13 +548,13 @@ definitions:
id:
type: string
privilege:
- $ref: '#/definitions/models.PrivilegeKey'
+ $ref: '#/definitions/PrivilegeKey'
reason:
type: string
user_id:
type: string
type: object
- models.UserRole:
+ UserRole:
properties:
granted_at:
type: string
@@ -450,7 +567,7 @@ definitions:
user_id:
type: string
type: object
- models.UserStatus:
+ UserStatus:
enum:
- ACTIVE
- INACTIVE
@@ -462,7 +579,7 @@ definitions:
- UserInactive
- UserSuspended
- UserMerged
- server.attachResourceRequest:
+ attachResourceRequest:
properties:
compute_allocation_resource_id:
type: string
@@ -471,57 +588,57 @@ definitions:
resource_time:
type: integer
type: object
- server.createRoleRequest:
+ createRoleRequest:
properties:
description:
type: string
name:
type: string
type: object
- server.grantPrivilegeRequest:
+ grantPrivilegeRequest:
properties:
privilege:
- $ref: '#/definitions/models.PrivilegeKey'
+ $ref: '#/definitions/PrivilegeKey'
reason:
type: string
type: object
- server.grantRoleRequest:
+ grantRoleRequest:
properties:
reason:
type: string
roleID:
type: string
type: object
- server.mergeUsersRequest:
+ mergeUsersRequest:
properties:
retiring_user_id:
type: string
surviving_user_id:
type: string
type: object
- server.revokePrivilegeRequest:
+ revokePrivilegeRequest:
properties:
reason:
type: string
type: object
- server.revokeRoleRequest:
+ revokeRoleRequest:
properties:
reason:
type: string
type: object
- server.rolePrivilegeRequest:
+ rolePrivilegeRequest:
properties:
privilege:
- $ref: '#/definitions/models.PrivilegeKey'
+ $ref: '#/definitions/PrivilegeKey'
type: object
- server.updateAllocationResourceMappingRequest:
+ updateAllocationResourceMappingRequest:
properties:
resource_amount:
type: integer
resource_time:
type: integer
type: object
- server.updateRoleRequest:
+ updateRoleRequest:
properties:
description:
type: string
@@ -559,7 +676,7 @@ paths:
properties:
events:
items:
- $ref: '#/definitions/models.TraceEvent'
+ $ref: '#/definitions/TraceEvent'
type: array
type: object
"400":
@@ -661,7 +778,7 @@ paths:
type: integer
traces:
items:
- $ref: '#/definitions/models.TraceSummary'
+ $ref: '#/definitions/TraceSummary'
type: array
type: object
"400":
@@ -702,7 +819,7 @@ paths:
type: string
tree:
items:
- $ref: '#/definitions/models.TraceNode'
+ $ref: '#/definitions/TraceNode'
type: array
truncated:
type: boolean
@@ -743,14 +860,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.ComputeAllocationChangeRequestEvent'
+ $ref: '#/definitions/ComputeAllocationChangeRequestEvent'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.ComputeAllocationChangeRequestEvent'
+ $ref: '#/definitions/ComputeAllocationChangeRequestEvent'
"400":
description: Bad Request
schema:
@@ -799,7 +916,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationChangeRequestEvent'
+ $ref: '#/definitions/ComputeAllocationChangeRequestEvent'
"404":
description: Not Found
schema:
@@ -822,14 +939,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.ComputeAllocationChangeRequest'
+ $ref: '#/definitions/ComputeAllocationChangeRequest'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.ComputeAllocationChangeRequest'
+ $ref: '#/definitions/ComputeAllocationChangeRequest'
"400":
description: Bad Request
schema:
@@ -878,7 +995,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationChangeRequest'
+ $ref: '#/definitions/ComputeAllocationChangeRequest'
"404":
description: Not Found
schema:
@@ -905,14 +1022,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.ComputeAllocationChangeRequest'
+ $ref: '#/definitions/ComputeAllocationChangeRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationChangeRequest'
+ $ref: '#/definitions/ComputeAllocationChangeRequest'
"400":
description: Bad Request
schema:
@@ -947,7 +1064,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeAllocationChangeRequestEvent'
+ $ref: '#/definitions/ComputeAllocationChangeRequestEvent'
type: array
"404":
description: Not Found
@@ -975,7 +1092,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationChangeRequestEvent'
+ $ref: '#/definitions/ComputeAllocationChangeRequestEvent'
"404":
description: Not Found
schema:
@@ -1000,14 +1117,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.ComputeAllocationDiff'
+ $ref: '#/definitions/ComputeAllocationDiff'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.ComputeAllocationDiff'
+ $ref: '#/definitions/ComputeAllocationDiff'
"400":
description: Bad Request
schema:
@@ -1063,7 +1180,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationDiff'
+ $ref: '#/definitions/ComputeAllocationDiff'
"404":
description: Not Found
schema:
@@ -1086,14 +1203,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.ComputeAllocationMembershipResourceOverride'
+ $ref: '#/definitions/ComputeAllocationMembershipResourceOverride'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.ComputeAllocationMembershipResourceOverride'
+ $ref: '#/definitions/ComputeAllocationMembershipResourceOverride'
"400":
description: Bad Request
schema:
@@ -1142,7 +1259,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationMembershipResourceOverride'
+ $ref: '#/definitions/ComputeAllocationMembershipResourceOverride'
"404":
description: Not Found
schema:
@@ -1169,14 +1286,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.ComputeAllocationMembershipResourceOverride'
+ $ref: '#/definitions/ComputeAllocationMembershipResourceOverride'
produces:
- application/json
responses:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationMembershipResourceOverride'
+ $ref: '#/definitions/ComputeAllocationMembershipResourceOverride'
"400":
description: Bad Request
schema:
@@ -1206,14 +1323,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.ComputeAllocationMembership'
+ $ref: '#/definitions/ComputeAllocationMembership'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.ComputeAllocationMembership'
+ $ref: '#/definitions/ComputeAllocationMembership'
"400":
description: Bad Request
schema:
@@ -1262,7 +1379,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationMembership'
+ $ref: '#/definitions/ComputeAllocationMembership'
"404":
description: Not Found
schema:
@@ -1289,14 +1406,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.ComputeAllocationMembership'
+ $ref: '#/definitions/ComputeAllocationMembership'
produces:
- application/json
responses:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationMembership'
+ $ref: '#/definitions/ComputeAllocationMembership'
"400":
description: Bad Request
schema:
@@ -1331,7 +1448,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeAllocationMembershipResourceOverride'
+ $ref: '#/definitions/ComputeAllocationMembershipResourceOverride'
type: array
"404":
description: Not Found
@@ -1362,7 +1479,7 @@ paths:
schema:
properties:
membership_status:
- $ref: '#/definitions/models.AllocationStatus'
+ $ref: '#/definitions/AllocationStatus'
type: object
produces:
- application/json
@@ -1370,7 +1487,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationMembership'
+ $ref: '#/definitions/ComputeAllocationMembership'
"400":
description: Bad Request
schema:
@@ -1402,14 +1519,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.ComputeAllocationResourceRate'
+ $ref: '#/definitions/ComputeAllocationResourceRate'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.ComputeAllocationResourceRate'
+ $ref: '#/definitions/ComputeAllocationResourceRate'
"400":
description: Bad Request
schema:
@@ -1443,7 +1560,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationResourceRate'
+ $ref: '#/definitions/ComputeAllocationResourceRate'
"404":
description: Not Found
schema:
@@ -1465,7 +1582,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeAllocationResource'
+ $ref: '#/definitions/ComputeAllocationResource'
type: array
"401":
description: Unauthorized
@@ -1490,14 +1607,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.ComputeAllocationResource'
+ $ref: '#/definitions/ComputeAllocationResource'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.ComputeAllocationResource'
+ $ref: '#/definitions/ComputeAllocationResource'
"400":
description: Bad Request
schema:
@@ -1531,7 +1648,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationResource'
+ $ref: '#/definitions/ComputeAllocationResource'
"404":
description: Not Found
schema:
@@ -1559,7 +1676,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeAllocationResourceMapping'
+ $ref: '#/definitions/ComputeAllocationResourceMapping'
type: array
"404":
description: Not Found
@@ -1588,7 +1705,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeAllocationMembershipResourceOverride'
+ $ref: '#/definitions/ComputeAllocationMembershipResourceOverride'
type: array
"404":
description: Not Found
@@ -1617,7 +1734,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeAllocationResourceRate'
+ $ref: '#/definitions/ComputeAllocationResourceRate'
type: array
"404":
description: Not Found
@@ -1651,7 +1768,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationResourceRate'
+ $ref: '#/definitions/ComputeAllocationResourceRate'
"400":
description: Invalid 'at' query parameter
schema:
@@ -1681,14 +1798,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.ComputeAllocationUsage'
+ $ref: '#/definitions/ComputeAllocationUsage'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.ComputeAllocationUsage'
+ $ref: '#/definitions/ComputeAllocationUsage'
"400":
description: Bad Request
schema:
@@ -1737,7 +1854,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationUsage'
+ $ref: '#/definitions/ComputeAllocationUsage'
"404":
description: Not Found
schema:
@@ -1751,6 +1868,40 @@ paths:
tags:
- Compute Allocation Usages
/compute-allocations:
+ get:
+ parameters:
+ - description: Filter by project ID
+ in: query
+ name: project_id
+ type: string
+ - description: Filter by status
+ in: query
+ name: status
+ type: string
+ - description: Search name
+ in: query
+ name: q
+ type: string
+ - description: Page size
+ in: query
+ name: limit
+ type: integer
+ - description: Page offset
+ in: query
+ name: offset
+ type: integer
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/ComputeAllocationListResponse'
+ security:
+ - CustosUserHeader: []
+ summary: List compute allocations (filtered + paginated)
+ tags:
+ - Compute Allocations
post:
consumes:
- application/json
@@ -1760,14 +1911,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.ComputeAllocation'
+ $ref: '#/definitions/ComputeAllocation'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.ComputeAllocation'
+ $ref: '#/definitions/ComputeAllocation'
"400":
description: Bad Request
schema:
@@ -1794,7 +1945,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocation'
+ $ref: '#/definitions/ComputeAllocation'
"404":
description: Not Found
schema:
@@ -1822,7 +1973,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeAllocationChangeRequest'
+ $ref: '#/definitions/ComputeAllocationChangeRequest'
type: array
"404":
description: Not Found
@@ -1851,7 +2002,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeAllocationDiff'
+ $ref: '#/definitions/ComputeAllocationDiff'
type: array
"404":
description: Not Found
@@ -1879,7 +2030,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationDiff'
+ $ref: '#/definitions/ComputeAllocationDiff'
"404":
description: Not Found
schema:
@@ -1907,7 +2058,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeAllocationMembership'
+ $ref: '#/definitions/AllocationMembershipResponse'
type: array
"404":
description: Not Found
@@ -1936,7 +2087,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeAllocationResourceMapping'
+ $ref: '#/definitions/ComputeAllocationResourceMapping'
type: array
"404":
description: Not Found
@@ -1966,14 +2117,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/server.attachResourceRequest'
+ $ref: '#/definitions/attachResourceRequest'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.ComputeAllocationResourceMapping'
+ $ref: '#/definitions/ComputeAllocationResourceMapping'
"400":
description: Bad Request
schema:
@@ -2040,14 +2191,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/server.updateAllocationResourceMappingRequest'
+ $ref: '#/definitions/updateAllocationResourceMappingRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeAllocationResourceMapping'
+ $ref: '#/definitions/ComputeAllocationResourceMapping'
"400":
description: Bad Request
schema:
@@ -2082,7 +2233,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeAllocationUsage'
+ $ref: '#/definitions/ComputeAllocationUsage'
type: array
"404":
description: Not Found
@@ -2110,12 +2261,7 @@ paths:
"200":
description: OK
schema:
- properties:
- compute_allocation_id:
- type: string
- total_su_amount:
- type: integer
- type: object
+ $ref: '#/definitions/AllocationSUTotalResponse'
"404":
description: Not Found
schema:
@@ -2147,14 +2293,7 @@ paths:
"200":
description: OK
schema:
- properties:
- compute_allocation_id:
- type: string
- total_su_amount:
- type: integer
- user_id:
- type: string
- type: object
+ $ref: '#/definitions/UserAllocationSUTotalResponse'
"404":
description: Not Found
schema:
@@ -2177,14 +2316,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.ComputeClusterUser'
+ $ref: '#/definitions/ComputeClusterUser'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.ComputeClusterUser'
+ $ref: '#/definitions/ComputeClusterUser'
"400":
description: Bad Request
schema:
@@ -2233,7 +2372,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeClusterUser'
+ $ref: '#/definitions/ComputeClusterUser'
"404":
description: Not Found
schema:
@@ -2260,14 +2399,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.ComputeClusterUser'
+ $ref: '#/definitions/ComputeClusterUser'
produces:
- application/json
responses:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeClusterUser'
+ $ref: '#/definitions/ComputeClusterUser'
"400":
description: Bad Request
schema:
@@ -2296,7 +2435,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeCluster'
+ $ref: '#/definitions/ComputeCluster'
type: array
"500":
description: Internal Server Error
@@ -2319,14 +2458,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.ComputeCluster'
+ $ref: '#/definitions/ComputeCluster'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.ComputeCluster'
+ $ref: '#/definitions/ComputeCluster'
"400":
description: Bad Request
schema:
@@ -2353,7 +2492,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeCluster'
+ $ref: '#/definitions/ComputeCluster'
"404":
description: Not Found
schema:
@@ -2381,7 +2520,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeClusterUser'
+ $ref: '#/definitions/ComputeClusterUser'
type: array
"404":
description: Not Found
@@ -2414,7 +2553,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.ComputeClusterUser'
+ $ref: '#/definitions/ComputeClusterUser'
"404":
description: Not Found
schema:
@@ -2437,14 +2576,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.Organization'
+ $ref: '#/definitions/Organization'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.Organization'
+ $ref: '#/definitions/Organization'
"400":
description: Bad Request
schema:
@@ -2471,7 +2610,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.Organization'
+ $ref: '#/definitions/Organization'
"404":
description: Not Found
schema:
@@ -2509,7 +2648,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.UserPrivilege'
+ $ref: '#/definitions/UserPrivilege'
type: array
"400":
description: Unknown privilege key
@@ -2532,7 +2671,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.PrivilegeKey'
+ $ref: '#/definitions/PrivilegeKey'
type: array
"401":
description: Missing caller header
@@ -2554,6 +2693,40 @@ paths:
tags:
- Privileges
/projects:
+ get:
+ parameters:
+ - description: Filter by PI user ID
+ in: query
+ name: pi_id
+ type: string
+ - description: Filter by status
+ in: query
+ name: status
+ type: string
+ - description: Search title / originated_id
+ in: query
+ name: q
+ type: string
+ - description: Page size
+ in: query
+ name: limit
+ type: integer
+ - description: Page offset
+ in: query
+ name: offset
+ type: integer
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/ProjectListResponse'
+ security:
+ - CustosUserHeader: []
+ summary: List projects (filtered + paginated, PI joined)
+ tags:
+ - Projects
post:
consumes:
- application/json
@@ -2563,14 +2736,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.Project'
+ $ref: '#/definitions/Project'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.Project'
+ $ref: '#/definitions/Project'
"400":
description: Bad Request
schema:
@@ -2597,7 +2770,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.Project'
+ $ref: '#/definitions/ProjectResponse'
"404":
description: Not Found
schema:
@@ -2610,6 +2783,35 @@ paths:
summary: Get a project by ID
tags:
- Projects
+ /projects/{id}/members:
+ get:
+ parameters:
+ - description: Project ID
+ in: path
+ name: id
+ required: true
+ type: string
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ items:
+ $ref: '#/definitions/ProjectMemberResponse'
+ type: array
+ "404":
+ description: Not Found
+ schema:
+ properties:
+ error:
+ type: string
+ type: object
+ security:
+ - CustosUserHeader: []
+ summary: List project members (one row per distinct user, with allocations)
+ tags:
+ - Projects
/projects/{id}/status:
put:
consumes:
@@ -2627,7 +2829,7 @@ paths:
schema:
properties:
status:
- $ref: '#/definitions/models.ProjectStatus'
+ $ref: '#/definitions/ProjectStatus'
type: object
produces:
- application/json
@@ -2635,7 +2837,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.Project'
+ $ref: '#/definitions/Project'
"400":
description: Bad Request
schema:
@@ -2664,7 +2866,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.Role'
+ $ref: '#/definitions/Role'
type: array
"401":
description: Unauthorized
@@ -2694,14 +2896,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/server.createRoleRequest'
+ $ref: '#/definitions/createRoleRequest'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.Role'
+ $ref: '#/definitions/Role'
"400":
description: Bad Request
schema:
@@ -2776,10 +2978,10 @@ paths:
properties:
privileges:
items:
- $ref: '#/definitions/models.PrivilegeKey'
+ $ref: '#/definitions/PrivilegeKey'
type: array
role:
- $ref: '#/definitions/models.Role'
+ $ref: '#/definitions/Role'
type: object
"400":
description: Bad Request
@@ -2815,14 +3017,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/server.updateRoleRequest'
+ $ref: '#/definitions/updateRoleRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
- $ref: '#/definitions/models.Role'
+ $ref: '#/definitions/Role'
"400":
description: Bad Request
schema:
@@ -2857,7 +3059,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.UserRole'
+ $ref: '#/definitions/UserRole'
type: array
"400":
description: Bad Request
@@ -2887,7 +3089,7 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/server.rolePrivilegeRequest'
+ $ref: '#/definitions/rolePrivilegeRequest'
responses:
"204":
description: No Content
@@ -2980,14 +3182,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.UserIdentity'
+ $ref: '#/definitions/UserIdentity'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.UserIdentity'
+ $ref: '#/definitions/UserIdentity'
"400":
description: Bad Request
schema:
@@ -3036,7 +3238,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.UserIdentity'
+ $ref: '#/definitions/UserIdentity'
"404":
description: Not Found
schema:
@@ -3063,14 +3265,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.UserIdentity'
+ $ref: '#/definitions/UserIdentity'
produces:
- application/json
responses:
"200":
description: OK
schema:
- $ref: '#/definitions/models.UserIdentity'
+ $ref: '#/definitions/UserIdentity'
"400":
description: Bad Request
schema:
@@ -3104,7 +3306,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.UserIdentity'
+ $ref: '#/definitions/UserIdentity'
"404":
description: Not Found
schema:
@@ -3136,7 +3338,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.UserIdentity'
+ $ref: '#/definitions/UserIdentity'
"404":
description: Not Found
schema:
@@ -3162,7 +3364,7 @@ paths:
properties:
privileges:
items:
- $ref: '#/definitions/models.PrivilegeKey'
+ $ref: '#/definitions/PrivilegeKey'
type: array
type: object
"401":
@@ -3194,14 +3396,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/models.User'
+ $ref: '#/definitions/User'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.User'
+ $ref: '#/definitions/User'
"400":
description: Bad Request
schema:
@@ -3228,7 +3430,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.User'
+ $ref: '#/definitions/User'
"404":
description: Not Found
schema:
@@ -3256,7 +3458,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeAllocationChangeRequest'
+ $ref: '#/definitions/ComputeAllocationChangeRequest'
type: array
"404":
description: Not Found
@@ -3285,7 +3487,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeAllocationMembership'
+ $ref: '#/definitions/ComputeAllocationMembership'
type: array
"404":
description: Not Found
@@ -3314,7 +3516,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeAllocationUsage'
+ $ref: '#/definitions/ComputeAllocationUsage'
type: array
"404":
description: Not Found
@@ -3343,7 +3545,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.ComputeClusterUser'
+ $ref: '#/definitions/ComputeClusterUser'
type: array
"404":
description: Not Found
@@ -3374,7 +3576,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.UserPrivilege'
+ $ref: '#/definitions/UserPrivilege'
type: array
"400":
description: Bad Request
@@ -3409,14 +3611,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/server.grantPrivilegeRequest'
+ $ref: '#/definitions/grantPrivilegeRequest'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.UserPrivilege'
+ $ref: '#/definitions/UserPrivilege'
"400":
description: Bad request
schema:
@@ -3480,7 +3682,7 @@ paths:
in: body
name: request
schema:
- $ref: '#/definitions/server.revokePrivilegeRequest'
+ $ref: '#/definitions/revokePrivilegeRequest'
responses:
"204":
description: No Content
@@ -3532,7 +3734,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.UserRole'
+ $ref: '#/definitions/UserRole'
type: array
"400":
description: Bad Request
@@ -3560,14 +3762,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/server.grantRoleRequest'
+ $ref: '#/definitions/grantRoleRequest'
produces:
- application/json
responses:
"201":
description: Created
schema:
- $ref: '#/definitions/models.UserRole'
+ $ref: '#/definitions/UserRole'
"400":
description: Bad Request
schema:
@@ -3615,7 +3817,7 @@ paths:
in: body
name: request
schema:
- $ref: '#/definitions/server.revokeRoleRequest'
+ $ref: '#/definitions/revokeRoleRequest'
responses:
"204":
description: No Content
@@ -3662,7 +3864,7 @@ paths:
schema:
properties:
status:
- $ref: '#/definitions/models.UserStatus'
+ $ref: '#/definitions/UserStatus'
type: object
produces:
- application/json
@@ -3670,7 +3872,7 @@ paths:
"200":
description: OK
schema:
- $ref: '#/definitions/models.User'
+ $ref: '#/definitions/User'
"400":
description: Bad Request
schema:
@@ -3705,7 +3907,7 @@ paths:
description: OK
schema:
items:
- $ref: '#/definitions/models.UserIdentity'
+ $ref: '#/definitions/UserIdentity'
type: array
"404":
description: Not Found
@@ -3731,14 +3933,14 @@ paths:
name: request
required: true
schema:
- $ref: '#/definitions/server.mergeUsersRequest'
+ $ref: '#/definitions/mergeUsersRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
- $ref: '#/definitions/models.User'
+ $ref: '#/definitions/User'
"400":
description: Bad Request
schema:
diff --git a/cmd/server/main.go b/cmd/server/main.go
index 7d75f2286..2287f100c 100644
--- a/cmd/server/main.go
+++ b/cmd/server/main.go
@@ -18,7 +18,7 @@
// Command server starts the Custos HTTP API.
package main
-//go:generate go run github.com/swaggo/swag/cmd/swag init -g main.go -d .,../../internal/server,../../pkg/models -o ../../api --outputTypes yaml --parseDependency
+//go:generate go run github.com/swaggo/swag/cmd/swag init -g main.go -d .,../../internal/server,../../pkg/models -o ../../api --outputTypes yaml --parseDependency --useStructName
//go:generate mv ../../api/swagger.yaml ../../api/core.openapi.yaml
import (
diff --git a/config/custos.yaml b/config/custos.yaml
index 11508d05e..ca8e749f1 100644
--- a/config/custos.yaml
+++ b/config/custos.yaml
@@ -1,6 +1,6 @@
core:
database:
- url: "admin:admin@tcp(localhost:3306)/custos?parseTime=true&charset=utf8mb4"
+ url: "${DATABASE_DSN}"
api:
port: 8080
log_level: "info"
@@ -29,15 +29,15 @@ connectors:
type: "comanage-identity-provisioner"
enabled: true
registry:
- url: "https://comanage.example.org"
- co_id: 1
- api_user: "comanage_api_user"
- api_key: "${COMANAGE_API_KEY}" # Reference to environment variable
+ url: "${COMANAGE_REGISTRY_URL}"
+ co_id: ${COMANAGE_CO_ID}
+ api_user: "${COMANAGE_API_USER}"
+ api_key: "${COMANAGE_API_KEY}"
unix_cluster:
- id: 10
- person_id_type: "eppn" # Educational Person Principal Name
+ id: ${COMANAGE_UNIX_CLUSTER_ID}
+ person_id_type: "${COMANAGE_PERSON_ID_TYPE}"
provisioning:
- custos_cluster_id: "cluster-001"
+ custos_cluster_id: "${CUSTOS_CLUSTER_ID}"
default_shell: "/bin/bash"
homedir_prefix: "/home/"
http_timeout: "30s"
@@ -46,11 +46,11 @@ connectors:
type: "amie-processor"
enabled: true
credentials:
- base_url: "https://amie.xsede.org"
- site_code: "XSEDE"
- api_key: "${AMIE_API_KEY}" # Reference to environment variable
+ base_url: "${AMIE_BASE_URL}"
+ site_code: "${AMIE_SITE_CODE}"
+ api_key: "${AMIE_API_KEY}"
cluster:
- id: "cluster-001" # Must match a cluster registered in Custos
+ id: "${AMIE_CLUSTER_ID}"
polling:
poll_interval: "30s"
worker_interval: "5s"
diff --git a/connectors/ACCESS/AMIE-Processor/handler/request_account_create.go b/connectors/ACCESS/AMIE-Processor/handler/request_account_create.go
index d4fb916c4..ed8ade5bc 100644
--- a/connectors/ACCESS/AMIE-Processor/handler/request_account_create.go
+++ b/connectors/ACCESS/AMIE-Processor/handler/request_account_create.go
@@ -111,7 +111,7 @@ func (h *RequestAccountCreateHandler) Handle(ctx context.Context, tx *sql.Tx, pa
}
role := normalizeRole(getString(body, "UserRole"))
- membership, err := h.ensureMembership(ctx, allocation.ID, user.ID)
+ membership, err := h.ensureMembership(ctx, allocation.ID, user.ID, role)
if err != nil {
return fmt.Errorf("request_account_create: ensure membership: %w", err)
}
@@ -189,18 +189,33 @@ func (h *RequestAccountCreateHandler) ensureComputeClusterUser(ctx context.Conte
// ensureMembership returns the existing (allocation, user) membership or
// creates a new one. Idempotent for re-delivered packets.
-func (h *RequestAccountCreateHandler) ensureMembership(ctx context.Context, allocationID, userID string) (*models.ComputeAllocationMembership, error) {
+func (h *RequestAccountCreateHandler) ensureMembership(ctx context.Context, allocationID, userID, role string) (*models.ComputeAllocationMembership, error) {
existing, err := h.svc.ListMembersForAllocation(ctx, allocationID)
if err != nil {
return nil, fmt.Errorf("list memberships: %w", err)
}
for _, m := range existing {
if m.UserID == userID {
- return &m, nil
+ cm := m.ComputeAllocationMembership
+ return &cm, nil
}
}
return h.svc.CreateComputeAllocationMembership(ctx, &models.ComputeAllocationMembership{
ComputeAllocationID: allocationID,
UserID: userID,
+ Role: normalizeAMIERole(role),
})
}
+
+// normalizeAMIERole maps the AMIE role enum to the persisted role column. Any
+// unrecognized value collapses to MEMBER.
+func normalizeAMIERole(amieRole string) string {
+ switch amieRole {
+ case "PI", "CO_PI", "ALLOCATION_MANAGER", "MEMBER":
+ return amieRole
+ case "USER":
+ return "MEMBER"
+ default:
+ return "MEMBER"
+ }
+}
diff --git a/connectors/ACCESS/AMIE-Processor/handler/request_project_create.go b/connectors/ACCESS/AMIE-Processor/handler/request_project_create.go
index 66dc5ae77..e782d4dca 100644
--- a/connectors/ACCESS/AMIE-Processor/handler/request_project_create.go
+++ b/connectors/ACCESS/AMIE-Processor/handler/request_project_create.go
@@ -114,6 +114,16 @@ func (h *RequestProjectCreateHandler) Handle(ctx context.Context, tx *sql.Tx, pa
return fmt.Errorf("request_project_create: audit CREATE_ALLOCATION: %w", err)
}
+ piMembership, created, err := h.ensurePIMembership(ctx, allocation, pi.ID)
+ if err != nil {
+ return fmt.Errorf("request_project_create: ensure PI membership: %w", err)
+ }
+ if created {
+ if err := h.auditSvc.Log(ctx, tx, packet.ID, eventID, model.AuditCreateMembership, "compute_allocation_membership", piMembership.ID, "PI"); err != nil {
+ return fmt.Errorf("request_project_create: audit CREATE_MEMBERSHIP (PI): %w", err)
+ }
+ }
+
replyBody := map[string]any{
"ProjectID": project.ID,
"GrantNumber": grantNumber,
@@ -226,6 +236,35 @@ func (h *RequestProjectCreateHandler) ensureAllocation(ctx context.Context, body
})
}
+// ensurePIMembership asserts the PI as a role=PI membership on the allocation.
+// Returns (membership, created=true) when it inserted a new row, or
+// (existing, created=false) on redelivery. The service rejects a second
+// distinct PI on the same allocation.
+func (h *RequestProjectCreateHandler) ensurePIMembership(ctx context.Context, allocation *models.ComputeAllocation, piID string) (*models.ComputeAllocationMembership, bool, error) {
+ existing, err := h.svc.ListMembersForAllocation(ctx, allocation.ID)
+ if err != nil {
+ return nil, false, fmt.Errorf("list memberships: %w", err)
+ }
+ for _, m := range existing {
+ if m.UserID == piID {
+ cm := m.ComputeAllocationMembership
+ return &cm, false, nil
+ }
+ }
+ created, err := h.svc.CreateComputeAllocationMembership(ctx, &models.ComputeAllocationMembership{
+ ComputeAllocationID: allocation.ID,
+ UserID: piID,
+ Role: "PI",
+ StartTime: allocation.StartTime,
+ EndTime: allocation.EndTime,
+ MembershipStatus: models.ACTIVE,
+ })
+ if err != nil {
+ return nil, false, err
+ }
+ return created, true, nil
+}
+
// recordAllocationDiff writes a ComputeAllocationDiff for a re-delivered
// request_project_create against an existing allocation (the AMIE pattern for
// supplements / renewals / extensions / adjustments). DiffType is the upper-cased
diff --git a/connectors/ACCESS/AMIE-Processor/pkg/amie/loader.go b/connectors/ACCESS/AMIE-Processor/pkg/amie/loader.go
index 3ddddf8b7..96af76fdd 100644
--- a/connectors/ACCESS/AMIE-Processor/pkg/amie/loader.go
+++ b/connectors/ACCESS/AMIE-Processor/pkg/amie/loader.go
@@ -18,7 +18,7 @@
// Package amie wires the ACCESS-AMIE connector into the core binary.
package amie
-//go:generate go run github.com/swaggo/swag/cmd/swag init -g loader.go -d .,../../server,../../store -o ../../api --outputTypes yaml --parseDependency
+//go:generate go run github.com/swaggo/swag/cmd/swag init -g loader.go -d .,../../server,../../store -o ../../api --outputTypes yaml --parseDependency --useStructName
//go:generate mv ../../api/swagger.yaml ../../api/amie.openapi.yaml
import (
@@ -86,7 +86,7 @@ func LoadConnector(ctx context.Context, database *sqlx.DB, eventBus *events.Bus,
auditSvc := service.NewAuditService(corestore.NewAuditEventStore(database), auditExtras)
packetAuditStore := store.NewPacketAuditStore(database)
if mux != nil {
- amieserver.NewHandlers(packetAuditStore).RegisterRoutes(mux)
+ amieserver.NewHandlers(packetAuditStore, packetStore).RegisterRoutes(mux)
}
// One AMIE site is tied to one downstream cluster by protocol, so cluster
diff --git a/connectors/ACCESS/AMIE-Processor/server/handlers.go b/connectors/ACCESS/AMIE-Processor/server/handlers.go
index 408dda313..c77b4579b 100644
--- a/connectors/ACCESS/AMIE-Processor/server/handlers.go
+++ b/connectors/ACCESS/AMIE-Processor/server/handlers.go
@@ -22,22 +22,35 @@ import (
"encoding/json"
"errors"
"net/http"
+ "strconv"
"strings"
+ "time"
"github.com/apache/airavata-custos/connectors/ACCESS/AMIE-Processor/store"
)
type Handlers struct {
- audits store.PacketAuditStore
+ audits store.PacketAuditStore
+ packets store.PacketStore
}
-func NewHandlers(audits store.PacketAuditStore) *Handlers {
- return &Handlers{audits: audits}
+func NewHandlers(audits store.PacketAuditStore, packets store.PacketStore) *Handlers {
+ return &Handlers{audits: audits, packets: packets}
}
// RegisterRoutes attaches the AMIE connector's HTTP endpoints to mux.
func (h *Handlers) RegisterRoutes(mux *http.ServeMux) {
+ mux.HandleFunc("GET /connectors/amie/packets", h.listPackets)
+ mux.HandleFunc("GET /connectors/amie/packets/{id}", h.getPacket)
+ mux.HandleFunc("GET /connectors/amie/packets/{id}/events", h.listPacketEvents)
mux.HandleFunc("GET /connectors/amie/packets/{packet_id}/audits", h.listPacketAudits)
+ mux.HandleFunc("GET /connectors/amie/stats", h.getStats)
+ mux.HandleFunc("GET /connectors/amie/replies", h.listReplies)
+ mux.HandleFunc("GET /connectors/amie/unmapped", h.listUnmapped)
+ mux.HandleFunc("POST /connectors/amie/packets/{id}/retry", h.retryPacket)
+ mux.HandleFunc("POST /connectors/amie/packets/{id}/resolve", h.resolvePacket)
+ mux.HandleFunc("POST /connectors/amie/replies/{id}/retry", h.retryReply)
+ mux.HandleFunc("POST /connectors/amie/unmapped/{id}/link", h.linkUnmapped)
}
// @Summary List audit events for an AMIE packet
@@ -71,6 +84,198 @@ func (h *Handlers) listPacketAudits(w http.ResponseWriter, r *http.Request) {
})
}
+func (h *Handlers) listPackets(w http.ResponseWriter, r *http.Request) {
+ if h.packets == nil {
+ writeJSON(w, http.StatusOK, emptyPacketPage(parseLimit(r), parseOffset(r)))
+ return
+ }
+ f, err := parsePacketFilter(r)
+ if err != nil {
+ writeError(w, http.StatusBadRequest, err)
+ return
+ }
+ rows, total, err := h.packets.ListPackets(r.Context(), f)
+ if err != nil {
+ writeError(w, http.StatusInternalServerError, err)
+ return
+ }
+ items := make([]PacketResponse, 0, len(rows))
+ for _, p := range rows {
+ items = append(items, packetResponseFrom(p))
+ }
+ writeJSON(w, http.StatusOK, PacketListResponse{
+ Packets: items,
+ Total: total,
+ Limit: effectiveLimit(f.Limit),
+ Offset: f.Offset,
+ })
+}
+
+func (h *Handlers) getPacket(w http.ResponseWriter, r *http.Request) {
+ if h.packets == nil {
+ writeError(w, http.StatusNotFound, errors.New("not found"))
+ return
+ }
+ p, err := h.packets.FindByID(r.Context(), r.PathValue("id"))
+ if err != nil {
+ writeError(w, http.StatusInternalServerError, err)
+ return
+ }
+ if p == nil {
+ writeError(w, http.StatusNotFound, errors.New("not found"))
+ return
+ }
+ writeJSON(w, http.StatusOK, packetResponseFrom(*p))
+}
+
+func (h *Handlers) listPacketEvents(w http.ResponseWriter, r *http.Request) {
+ if h.packets == nil {
+ writeJSON(w, http.StatusOK, []PacketEventResponse{})
+ return
+ }
+ rows, err := h.packets.ListPacketEvents(r.Context(), r.PathValue("id"))
+ if err != nil {
+ writeError(w, http.StatusInternalServerError, err)
+ return
+ }
+ out := make([]PacketEventResponse, 0, len(rows))
+ for _, e := range rows {
+ out = append(out, packetEventResponseFrom(e))
+ }
+ writeJSON(w, http.StatusOK, out)
+}
+
+func (h *Handlers) getStats(w http.ResponseWriter, r *http.Request) {
+ if h.packets == nil {
+ writeJSON(w, http.StatusOK, PacketStatsResponse{ByDay: []PacketStatBucketResponse{}})
+ return
+ }
+ window := parseWindow(r.URL.Query().Get("window"))
+ buckets, err := h.packets.GetStats(r.Context(), window)
+ if err != nil {
+ writeError(w, http.StatusInternalServerError, err)
+ return
+ }
+ writeJSON(w, http.StatusOK, packetStatsResponseFrom(buckets))
+}
+
+// ReplyListResponse is the paginated list envelope for connector replies.
+type ReplyListResponse struct {
+ Replies []any `json:"replies"`
+ Total int `json:"total"`
+ Limit int `json:"limit"`
+ Offset int `json:"offset"`
+}
+
+func (h *Handlers) listReplies(w http.ResponseWriter, r *http.Request) {
+ writeJSON(w, http.StatusOK, ReplyListResponse{
+ Replies: []any{},
+ Total: 0,
+ Limit: effectiveLimit(parseLimit(r)),
+ Offset: parseOffset(r),
+ })
+}
+
+func (h *Handlers) listUnmapped(w http.ResponseWriter, r *http.Request) {
+ writeJSON(w, http.StatusOK, emptyPacketPage(parseLimit(r), parseOffset(r)))
+}
+
+func (h *Handlers) retryPacket(w http.ResponseWriter, _ *http.Request) {
+ writeNotImplemented(w, "packet retry")
+}
+func (h *Handlers) resolvePacket(w http.ResponseWriter, _ *http.Request) {
+ writeNotImplemented(w, "packet resolve")
+}
+func (h *Handlers) retryReply(w http.ResponseWriter, _ *http.Request) {
+ writeNotImplemented(w, "reply retry")
+}
+func (h *Handlers) linkUnmapped(w http.ResponseWriter, _ *http.Request) {
+ writeNotImplemented(w, "unmapped link")
+}
+
+func writeNotImplemented(w http.ResponseWriter, op string) {
+ writeJSON(w, http.StatusNotImplemented, map[string]string{
+ "error": "not_implemented",
+ "message": op + " not supported on this branch",
+ })
+}
+
+func emptyPacketPage(limit, offset int) PacketListResponse {
+ return PacketListResponse{
+ Packets: []PacketResponse{},
+ Total: 0,
+ Limit: effectiveLimit(limit),
+ Offset: offset,
+ }
+}
+
+func parsePacketFilter(r *http.Request) (store.PacketListFilter, error) {
+ q := r.URL.Query()
+ f := store.PacketListFilter{
+ Status: q.Get("status"),
+ Type: q.Get("type"),
+ Query: q.Get("q"),
+ Limit: parseLimit(r),
+ Offset: parseOffset(r),
+ }
+ if v := q.Get("from"); v != "" {
+ t, err := time.Parse(time.RFC3339Nano, v)
+ if err != nil {
+ return f, errors.New("invalid 'from' query parameter; expected RFC 3339")
+ }
+ f.From = t
+ }
+ if v := q.Get("to"); v != "" {
+ t, err := time.Parse(time.RFC3339Nano, v)
+ if err != nil {
+ return f, errors.New("invalid 'to' query parameter; expected RFC 3339")
+ }
+ f.To = t
+ }
+ return f, nil
+}
+
+func parseLimit(r *http.Request) int {
+ if v := r.URL.Query().Get("limit"); v != "" {
+ if n, err := strconv.Atoi(v); err == nil && n >= 0 {
+ return n
+ }
+ }
+ return 0
+}
+
+func parseOffset(r *http.Request) int {
+ if v := r.URL.Query().Get("offset"); v != "" {
+ if n, err := strconv.Atoi(v); err == nil && n >= 0 {
+ return n
+ }
+ }
+ return 0
+}
+
+func effectiveLimit(l int) int {
+ if l <= 0 || l > 200 {
+ return 50
+ }
+ return l
+}
+
+func parseWindow(v string) time.Duration {
+ v = strings.TrimSpace(v)
+ if v == "" {
+ return 30 * 24 * time.Hour
+ }
+ if strings.HasSuffix(v, "d") {
+ if n, err := strconv.Atoi(strings.TrimSuffix(v, "d")); err == nil && n > 0 {
+ return time.Duration(n) * 24 * time.Hour
+ }
+ }
+ if d, err := time.ParseDuration(v); err == nil && d > 0 {
+ return d
+ }
+ return 30 * 24 * time.Hour
+}
+
func writeJSON(w http.ResponseWriter, status int, v any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
diff --git a/connectors/ACCESS/AMIE-Processor/server/handlers_test.go b/connectors/ACCESS/AMIE-Processor/server/handlers_test.go
index 49fb6f4c2..65b732c73 100644
--- a/connectors/ACCESS/AMIE-Processor/server/handlers_test.go
+++ b/connectors/ACCESS/AMIE-Processor/server/handlers_test.go
@@ -48,9 +48,9 @@ func newTestServer(t *testing.T, store *fakePacketAuditStore) *httptest.Server {
mux := http.NewServeMux()
var h *Handlers
if store == nil {
- h = NewHandlers(nil)
+ h = NewHandlers(nil, nil)
} else {
- h = NewHandlers(store)
+ h = NewHandlers(store, nil)
}
h.RegisterRoutes(mux)
srv := httptest.NewServer(mux)
diff --git a/connectors/ACCESS/AMIE-Processor/server/responses.go b/connectors/ACCESS/AMIE-Processor/server/responses.go
new file mode 100644
index 000000000..c9ce3177a
--- /dev/null
+++ b/connectors/ACCESS/AMIE-Processor/server/responses.go
@@ -0,0 +1,190 @@
+// 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 server
+
+import (
+ "strconv"
+ "strings"
+ "time"
+
+ "github.com/apache/airavata-custos/connectors/ACCESS/AMIE-Processor/model"
+ "github.com/apache/airavata-custos/connectors/ACCESS/AMIE-Processor/store"
+)
+
+// packetSource is the fixed source label until multi-source ingestion lands.
+const packetSource = "access"
+
+// PacketResponse is the wire shape for an AMIE packet.
+type PacketResponse struct {
+ ID string `json:"id"`
+ AmieID string `json:"amie_id"`
+ Type string `json:"type"`
+ Status string `json:"status"`
+ Source string `json:"source"`
+ RawJSON *string `json:"raw_json,omitempty"`
+ ReceivedAt string `json:"received_at"`
+ UpdatedAt string `json:"updated_at"`
+ DecodedAt *string `json:"decoded_at,omitempty"`
+ ProcessedAt *string `json:"processed_at,omitempty"`
+ Retries int `json:"retries"`
+ LastError *string `json:"last_error,omitempty"`
+}
+
+// PacketListResponse is the paginated list envelope for packets.
+type PacketListResponse struct {
+ Packets []PacketResponse `json:"packets"`
+ Total int `json:"total"`
+ Limit int `json:"limit"`
+ Offset int `json:"offset"`
+}
+
+// PacketEventResponse is the wire shape for a packet processing event.
+type PacketEventResponse struct {
+ ID string `json:"id"`
+ PacketID string `json:"packet_id"`
+ EventType string `json:"event_type"`
+ Actor string `json:"actor"`
+ Status string `json:"status"`
+ Message *string `json:"message,omitempty"`
+ Timestamp string `json:"timestamp"`
+ DurationMs *int64 `json:"duration_ms,omitempty"`
+}
+
+// PacketStatBucketResponse is a single (date, status, type) cell in the stats grid.
+type PacketStatBucketResponse struct {
+ Date string `json:"date"`
+ Status string `json:"status"`
+ Type string `json:"type"`
+ Count int64 `json:"count"`
+}
+
+// PacketStatsResponse is the per-day packet stats payload.
+type PacketStatsResponse struct {
+ ByDay []PacketStatBucketResponse `json:"byDay"`
+}
+
+// packetResponseFrom maps a stored Packet to its wire shape.
+func packetResponseFrom(p model.Packet) PacketResponse {
+ out := PacketResponse{
+ ID: p.ID,
+ AmieID: strconv.FormatInt(p.AmieID, 10),
+ Type: p.Type,
+ Status: string(p.Status),
+ Source: packetSource,
+ ReceivedAt: p.ReceivedAt.UTC().Format(time.RFC3339Nano),
+ Retries: p.Retries,
+ LastError: p.LastError,
+ }
+ if p.RawJSON != "" {
+ v := p.RawJSON
+ out.RawJSON = &v
+ }
+ if p.DecodedAt != nil {
+ v := p.DecodedAt.UTC().Format(time.RFC3339Nano)
+ out.DecodedAt = &v
+ }
+ if p.ProcessedAt != nil {
+ v := p.ProcessedAt.UTC().Format(time.RFC3339Nano)
+ out.ProcessedAt = &v
+ }
+ out.UpdatedAt = mostRecent(p.ReceivedAt, p.DecodedAt, p.ProcessedAt).UTC().Format(time.RFC3339Nano)
+ return out
+}
+
+// packetEventResponseFrom maps a stored ProcessingEvent to its wire shape.
+func packetEventResponseFrom(e model.ProcessingEvent) PacketEventResponse {
+ ts := e.CreatedAt
+ if e.StartedAt != nil {
+ ts = *e.StartedAt
+ }
+ out := PacketEventResponse{
+ ID: e.ID,
+ PacketID: e.PacketID,
+ EventType: mapEventType(string(e.Type), string(e.Status)),
+ Actor: "amie-worker",
+ Status: mapEventStatus(string(e.Status)),
+ Timestamp: ts.UTC().Format(time.RFC3339Nano),
+ Message: e.LastError,
+ }
+ if e.StartedAt != nil && e.FinishedAt != nil {
+ d := e.FinishedAt.Sub(*e.StartedAt).Milliseconds()
+ if d >= 0 {
+ out.DurationMs = &d
+ }
+ }
+ return out
+}
+
+// packetStatsResponseFrom wraps neutral stat buckets in the portal envelope.
+func packetStatsResponseFrom(buckets []store.StatBucket) PacketStatsResponse {
+ out := PacketStatsResponse{ByDay: make([]PacketStatBucketResponse, 0, len(buckets))}
+ for _, b := range buckets {
+ out.ByDay = append(out.ByDay, PacketStatBucketResponse{
+ Date: b.Date,
+ Status: b.Status,
+ Type: b.Type,
+ Count: b.Count,
+ })
+ }
+ return out
+}
+
+// mostRecent returns the latest of received and any provided optional times.
+func mostRecent(received time.Time, others ...*time.Time) time.Time {
+ latest := received
+ for _, o := range others {
+ if o != nil && o.After(latest) {
+ latest = *o
+ }
+ }
+ return latest
+}
+
+// mapEventType folds amie_processing_events.type into the portal's enum.
+func mapEventType(t, status string) string {
+ if strings.EqualFold(status, "FAILED") {
+ return "FAILED"
+ }
+ switch strings.ToLower(t) {
+ case "received":
+ return "RECEIVED"
+ case "decoded":
+ return "DECODED"
+ case "handled", "processed":
+ return "HANDLED"
+ case "retry_scheduled":
+ return "RETRY_SCHEDULED"
+ case "retry":
+ return "RETRY"
+ case "manual_resolve":
+ return "MANUAL_RESOLVE"
+ case "manual_link":
+ return "MANUAL_LINK"
+ }
+ return "HANDLED"
+}
+
+func mapEventStatus(s string) string {
+ switch strings.ToUpper(s) {
+ case "FAILED", "ERROR":
+ return "FAILED"
+ case "RUNNING", "STARTED", "IN_PROGRESS":
+ return "RUNNING"
+ }
+ return "SUCCEEDED"
+}
diff --git a/connectors/ACCESS/AMIE-Processor/store/packet_store.go b/connectors/ACCESS/AMIE-Processor/store/packet_store.go
index ddf57f2c6..1c196c5fa 100644
--- a/connectors/ACCESS/AMIE-Processor/store/packet_store.go
+++ b/connectors/ACCESS/AMIE-Processor/store/packet_store.go
@@ -21,16 +21,45 @@ import (
"context"
"database/sql"
"errors"
+ "fmt"
+ "strings"
+ "time"
"github.com/apache/airavata-custos/connectors/ACCESS/AMIE-Processor/model"
"github.com/jmoiron/sqlx"
)
+// PacketListFilter narrows the packet listing returned by ListPackets.
+type PacketListFilter struct {
+ Status string
+ Type string
+ Query string
+ From time.Time
+ To time.Time
+ Limit int
+ Offset int
+}
+
+// StatBucket is one row from the per-day (status, type) packet aggregation.
+type StatBucket struct {
+ Date string `db:"date"`
+ Status string `db:"status"`
+ Type string `db:"type"`
+ Count int64 `db:"count"`
+}
+
+// PacketStore is the data-access surface for the amie_packets table.
+// FindByAmieID/FindByID/Save/Update serve the worker pipeline.
+// ListPackets/ListPacketEvents/GetStats serve read endpoints.
type PacketStore interface {
FindByAmieID(ctx context.Context, amieID int64) (*model.Packet, error)
FindByID(ctx context.Context, id string) (*model.Packet, error)
Save(ctx context.Context, tx *sql.Tx, p *model.Packet) error
Update(ctx context.Context, tx *sql.Tx, p *model.Packet) error
+
+ ListPackets(ctx context.Context, f PacketListFilter) ([]model.Packet, int, error)
+ ListPacketEvents(ctx context.Context, packetID string) ([]model.ProcessingEvent, error)
+ GetStats(ctx context.Context, window time.Duration) ([]StatBucket, error)
}
type mariaDBPacketStore struct {
@@ -41,11 +70,12 @@ func NewPacketStore(db *sqlx.DB) PacketStore {
return &mariaDBPacketStore{db: db}
}
+const packetColumns = `id, amie_id, type, status, raw_json, received_at, decoded_at, processed_at, retries, last_error`
+
func (s *mariaDBPacketStore) FindByAmieID(ctx context.Context, amieID int64) (*model.Packet, error) {
var p model.Packet
err := s.db.GetContext(ctx, &p,
- `SELECT id, amie_id, type, status, raw_json, received_at, decoded_at, processed_at, retries, last_error
- FROM amie_packets WHERE amie_id = ?`, amieID)
+ `SELECT `+packetColumns+` FROM amie_packets WHERE amie_id = ?`, amieID)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, nil
@@ -58,8 +88,7 @@ func (s *mariaDBPacketStore) FindByAmieID(ctx context.Context, amieID int64) (*m
func (s *mariaDBPacketStore) FindByID(ctx context.Context, id string) (*model.Packet, error) {
var p model.Packet
err := s.db.GetContext(ctx, &p,
- `SELECT id, amie_id, type, status, raw_json, received_at, decoded_at, processed_at, retries, last_error
- FROM amie_packets WHERE id = ?`, id)
+ `SELECT `+packetColumns+` FROM amie_packets WHERE id = ?`, id)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, nil
@@ -87,3 +116,88 @@ func (s *mariaDBPacketStore) Update(ctx context.Context, tx *sql.Tx, p *model.Pa
p.Retries, p.LastError, p.ID)
return err
}
+
+func (s *mariaDBPacketStore) ListPackets(ctx context.Context, f PacketListFilter) ([]model.Packet, int, error) {
+ where, args := buildPacketFilter(f)
+
+ var total int
+ if err := s.db.GetContext(ctx, &total, `SELECT COUNT(*) FROM amie_packets`+where, args...); err != nil {
+ return nil, 0, err
+ }
+
+ limit := f.Limit
+ if limit <= 0 || limit > 200 {
+ limit = 50
+ }
+ offset := f.Offset
+ if offset < 0 {
+ offset = 0
+ }
+ q := fmt.Sprintf(`SELECT %s FROM amie_packets%s ORDER BY received_at DESC LIMIT %d OFFSET %d`,
+ packetColumns, where, limit, offset)
+
+ var rows []model.Packet
+ if err := s.db.SelectContext(ctx, &rows, q, args...); err != nil {
+ return nil, 0, err
+ }
+ return rows, total, nil
+}
+
+func buildPacketFilter(f PacketListFilter) (string, []any) {
+ var clauses []string
+ var args []any
+ if f.Status != "" && !strings.EqualFold(f.Status, "all") {
+ clauses = append(clauses, "status = ?")
+ args = append(args, f.Status)
+ }
+ if f.Type != "" {
+ clauses = append(clauses, "type = ?")
+ args = append(args, f.Type)
+ }
+ if f.Query != "" {
+ clauses = append(clauses, "(id LIKE ? OR CAST(amie_id AS CHAR) LIKE ?)")
+ like := "%" + f.Query + "%"
+ args = append(args, like, like)
+ }
+ if !f.From.IsZero() {
+ clauses = append(clauses, "received_at >= ?")
+ args = append(args, f.From)
+ }
+ if !f.To.IsZero() {
+ clauses = append(clauses, "received_at <= ?")
+ args = append(args, f.To)
+ }
+ if len(clauses) == 0 {
+ return "", args
+ }
+ return " WHERE " + strings.Join(clauses, " AND "), args
+}
+
+func (s *mariaDBPacketStore) ListPacketEvents(ctx context.Context, packetID string) ([]model.ProcessingEvent, error) {
+ var rows []model.ProcessingEvent
+ err := s.db.SelectContext(ctx, &rows,
+ `SELECT id, packet_id, type, status, attempts, payload, created_at, started_at, finished_at, last_error, next_retry_at
+ FROM amie_processing_events WHERE packet_id = ? ORDER BY created_at ASC`, packetID)
+ if err != nil {
+ return nil, err
+ }
+ return rows, nil
+}
+
+func (s *mariaDBPacketStore) GetStats(ctx context.Context, window time.Duration) ([]StatBucket, error) {
+ if window <= 0 {
+ window = 30 * 24 * time.Hour
+ }
+ since := time.Now().UTC().Add(-window)
+ var rows []StatBucket
+ err := s.db.SelectContext(ctx, &rows,
+ `SELECT DATE(received_at) AS date, status, type, COUNT(*) AS count
+ FROM amie_packets
+ WHERE received_at >= ?
+ GROUP BY DATE(received_at), status, type
+ ORDER BY date ASC`, since)
+ if err != nil {
+ return nil, err
+ }
+ return rows, nil
+}
diff --git a/connectors/COmanage/Identity-Provisioner/internal/client/client_test.go b/connectors/COmanage/Identity-Provisioner/internal/client/client_test.go
index 471aa606b..4baa33a29 100644
--- a/connectors/COmanage/Identity-Provisioner/internal/client/client_test.go
+++ b/connectors/COmanage/Identity-Provisioner/internal/client/client_test.go
@@ -190,6 +190,51 @@ func TestCreateUnixClusterGroup_URLAndBody(t *testing.T) {
}
}
+func TestFindUnixClusterGroup_MatchesConfiguredCluster(t *testing.T) {
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Query().Get("cogroupid") != "25" {
+ t.Errorf("missing cogroupid filter: %s", r.URL.RawQuery)
+ }
+ _, _ = io.WriteString(w, `{
+ "ResponseType":"UnixClusterGroups","Version":"1.0",
+ "UnixClusterGroups":[
+ {"Version":"1.0","Id":7,"UnixClusterId":9,"CoGroupId":25},
+ {"Version":"1.0","Id":8,"UnixClusterId":1,"CoGroupId":25}
+ ]
+ }`)
+ }))
+ defer srv.Close()
+
+ c := newTestClient(t, srv.URL)
+ c.cfg.RegistryURL = srv.URL
+
+ id, err := c.FindUnixClusterGroup(25)
+ if err != nil {
+ t.Fatalf("FindUnixClusterGroup: %v", err)
+ }
+ if id != 8 {
+ t.Errorf("id: got %d, want 8 (UnixClusterId=1 matches configured cluster)", id)
+ }
+}
+
+func TestFindUnixClusterGroup_NoMatchReturnsZero(t *testing.T) {
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ _, _ = io.WriteString(w, `{"ResponseType":"UnixClusterGroups","Version":"1.0","UnixClusterGroups":[]}`)
+ }))
+ defer srv.Close()
+
+ c := newTestClient(t, srv.URL)
+ c.cfg.RegistryURL = srv.URL
+
+ id, err := c.FindUnixClusterGroup(99)
+ if err != nil {
+ t.Fatalf("FindUnixClusterGroup: %v", err)
+ }
+ if id != 0 {
+ t.Errorf("id: got %d, want 0", id)
+ }
+}
+
func TestGetPersonComposite_PreservesRawJSON(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet || !strings.Contains(r.URL.Path, "/api/co/2/core/v1/people/Person100099") {
diff --git a/connectors/COmanage/Identity-Provisioner/internal/client/identifiers.go b/connectors/COmanage/Identity-Provisioner/internal/client/identifiers.go
index f562c2915..252d8d352 100644
--- a/connectors/COmanage/Identity-Provisioner/internal/client/identifiers.go
+++ b/connectors/COmanage/Identity-Provisioner/internal/client/identifiers.go
@@ -128,3 +128,32 @@ func (c *Client) FindIdentifierOnGroup(coGroupId int, identifierType string) (in
return 0, &HTTPError{Method: "GET", URL: u, StatusCode: resp.StatusCode, Body: string(respBody)}
}
}
+
+// FindIdentifierValueOnPerson returns the Identifier *value* (e.g. "Custos100022")
+// of the given type on a CoPerson, or "" if none is assigned yet.
+func (c *Client) FindIdentifierValueOnPerson(coPersonID int, identifierType string) (string, error) {
+ u := c.restAPI(fmt.Sprintf("/identifiers.json?copersonid=%d", coPersonID))
+ resp, respBody, err := c.Do(http.MethodGet, u, nil)
+ if err != nil {
+ return "", err
+ }
+ switch resp.StatusCode {
+ case http.StatusOK:
+ var out IdentifierListResponse
+ if err := json.Unmarshal(respBody, &out); err != nil {
+ return "", fmt.Errorf("decode identifiers list: %w", err)
+ }
+ for _, ident := range out.Identifiers {
+ if ident.Type == identifierType {
+ return ident.Identifier, nil
+ }
+ }
+ return "", nil
+ case http.StatusNoContent:
+ return "", nil
+ case http.StatusUnauthorized:
+ return "", ErrAuth401
+ default:
+ return "", &HTTPError{Method: "GET", URL: u, StatusCode: resp.StatusCode, Body: string(respBody)}
+ }
+}
diff --git a/connectors/COmanage/Identity-Provisioner/internal/client/unix_cluster.go b/connectors/COmanage/Identity-Provisioner/internal/client/unix_cluster.go
index 2a9eaa99d..6e8158be4 100644
--- a/connectors/COmanage/Identity-Provisioner/internal/client/unix_cluster.go
+++ b/connectors/COmanage/Identity-Provisioner/internal/client/unix_cluster.go
@@ -35,6 +35,50 @@ type UnixClusterGroupCreateOne struct {
CoGroupId int `json:"CoGroupId"`
}
+type UnixClusterGroupListResponse struct {
+ ResponseType string `json:"ResponseType"`
+ Version string `json:"Version"`
+ UnixClusterGroups []UnixClusterGroupReadOne `json:"UnixClusterGroups"`
+}
+
+type UnixClusterGroupReadOne struct {
+ Version string `json:"Version"`
+ Id int `json:"Id"`
+ UnixClusterId int `json:"UnixClusterId"`
+ CoGroupId int `json:"CoGroupId"`
+}
+
+// FindUnixClusterGroup returns the existing UnixClusterGroup binding id for the
+// configured UnixCluster + given CoGroup, or 0 if none. Used to make the
+// attached call idempotent: COmanage's UnixCluster plugin returns 500 (not 4xx)
+// on duplicate binding attempts.
+func (c *Client) FindUnixClusterGroup(coGroupId int) (int, error) {
+ u := c.restAPI(fmt.Sprintf("/unix_cluster/unix_cluster_groups.json?cogroupid=%d", coGroupId))
+ resp, respBody, err := c.Do(http.MethodGet, u, nil)
+ if err != nil {
+ return 0, err
+ }
+ switch resp.StatusCode {
+ case http.StatusOK:
+ var out UnixClusterGroupListResponse
+ if err := json.Unmarshal(respBody, &out); err != nil {
+ return 0, fmt.Errorf("decode unix_cluster_groups list: %w", err)
+ }
+ for _, g := range out.UnixClusterGroups {
+ if g.UnixClusterId == c.cfg.UnixClusterID {
+ return g.Id, nil
+ }
+ }
+ return 0, nil
+ case http.StatusNoContent:
+ return 0, nil
+ case http.StatusUnauthorized:
+ return 0, ErrAuth401
+ default:
+ return 0, &HTTPError{Method: "GET", URL: u, StatusCode: resp.StatusCode, Body: string(respBody)}
+ }
+}
+
// CreateUnixClusterGroup binds a CoGroup to a UnixCluster. The URL takes no
// named params for POST.
func (c *Client) CreateUnixClusterGroup(coGroupId int) (int, error) {
diff --git a/connectors/COmanage/Identity-Provisioner/internal/operations/ensure_posix_account.go b/connectors/COmanage/Identity-Provisioner/internal/operations/ensure_posix_account.go
index 264c5fd6b..e6efd3c94 100644
--- a/connectors/COmanage/Identity-Provisioner/internal/operations/ensure_posix_account.go
+++ b/connectors/COmanage/Identity-Provisioner/internal/operations/ensure_posix_account.go
@@ -23,7 +23,9 @@ import (
"errors"
"fmt"
"log/slog"
+ "net/http"
"strconv"
+ "time"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
@@ -99,7 +101,7 @@ func (o *Orchestrator) ensurePOSIXAccountImpl(ctx context.Context, cu *models.Co
if err := o.findOrCreateCoGroupMember(ctx, cu, coGroupID, coPersonID); err != nil {
return err
}
- if err := o.createUnixClusterGroup(ctx, cu, coGroupID, log); err != nil {
+ if err := o.findOrCreateUnixClusterGroup(ctx, cu, coGroupID, log); err != nil {
return err
}
@@ -218,21 +220,38 @@ func (o *Orchestrator) findOrCreateCoGroupMember(ctx context.Context, cu *models
return nil
}
-// createUnixClusterGroup re-attempts the bind; 4xx is treated as
-// already-attached and swallowed (idempotency mechanism).
-func (o *Orchestrator) createUnixClusterGroup(ctx context.Context, cu *models.ComputeClusterUser, coGroupID int, log *slog.Logger) error {
- _, span := tracing.Start(ctx, "comanage.create_unix_cluster_group")
+// findOrCreateUnixClusterGroup binds the CoGroup to the configured UnixCluster
+// idempotently. The UnixCluster plugin returns 500 on duplicate POSTs, so we
+// GET first; on a 500 from POST we re-GET to recover from races.
+func (o *Orchestrator) findOrCreateUnixClusterGroup(ctx context.Context, cu *models.ComputeClusterUser, coGroupID int, log *slog.Logger) error {
+ ctx, span := tracing.Start(ctx, "comanage.find_or_create_unix_cluster_group")
defer span.End()
span.SetAttributes(attribute.Int("comanage.co_group_id", coGroupID))
+
+ if existing, err := o.c.FindUnixClusterGroup(coGroupID); err == nil && existing != 0 {
+ span.SetAttributes(attribute.Int("comanage.unix_cluster_group_id", existing))
+ return nil
+ } else if err != nil {
+ log.Debug("comanage: FindUnixClusterGroup failed; attempting POST", "err", err)
+ }
+
if _, err := o.c.CreateUnixClusterGroup(coGroupID); err != nil {
var httpErr *client.HTTPError
- if !errors.As(err, &httpErr) || httpErr.StatusCode < 400 || httpErr.StatusCode >= 500 {
- span.RecordError(err)
- span.SetStatus(codes.Error, err.Error())
- o.dlq(ctx, cu, "create_unix_cluster_group", err)
- return err
+ if errors.As(err, &httpErr) && httpErr.StatusCode >= 400 && httpErr.StatusCode < 500 {
+ log.Info("comanage: UnixClusterGroup attach returned 4xx (already attached)", "status", httpErr.StatusCode)
+ return nil
}
- log.Info("comanage: UnixClusterGroup attach returned 4xx (already attached)", "status", httpErr.StatusCode)
+ if errors.As(err, &httpErr) && httpErr.StatusCode == http.StatusInternalServerError {
+ if existing, gerr := o.c.FindUnixClusterGroup(coGroupID); gerr == nil && existing != 0 {
+ log.Info("comanage: UnixClusterGroup POST returned 500 but binding exists", "binding_id", existing)
+ span.SetAttributes(attribute.Int("comanage.unix_cluster_group_id", existing))
+ return nil
+ }
+ }
+ span.RecordError(err)
+ span.SetStatus(codes.Error, err.Error())
+ o.dlq(ctx, cu, "create_unix_cluster_group", err)
+ return err
}
return nil
}
@@ -282,23 +301,29 @@ func (o *Orchestrator) lookupOrCreateCoPerson(ctx context.Context, user *models.
return "", nil, false, fmt.Errorf("email search: %w", err)
}
if coPersonID != 0 {
- composite, err := o.c.GetPersonComposite(strconv.Itoa(coPersonID))
+ // COmanage's /people/{identifier} endpoint expects an Identifier
+ // *value* (e.g. "Custos100022"), not a numeric CoPerson ID. Resolve
+ // the identifier value by listing the CoPerson's Identifiers first.
+ personID, err := o.c.FindIdentifierValueOnPerson(coPersonID, personIDType)
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
- return "", nil, false, fmt.Errorf("get composite by numeric id: %w", err)
- }
- personID, err := extractIdentifier(composite, personIDType)
- if err != nil {
- span.RecordError(err)
- span.SetStatus(codes.Error, err.Error())
- return "", nil, false, fmt.Errorf("extract %s from composite: %w", personIDType, err)
+ return "", nil, false, fmt.Errorf("find %s on CoPerson %d: %w", personIDType, coPersonID, err)
}
if personID == "" {
- return "", nil, false, fmt.Errorf("CoPerson %d has no %s identifier", coPersonID, personIDType)
+ // CoPerson exists but the identifier-assignment plugin hasn't
+ // run yet; fall through to POST /people (idempotent against
+ // repeat creation since COmanage dedups on the CoPersonRole).
+ } else {
+ composite, err := o.c.GetPersonComposite(personID)
+ if err != nil {
+ span.RecordError(err)
+ span.SetStatus(codes.Error, err.Error())
+ return "", nil, false, fmt.Errorf("get composite by %s %s: %w", personIDType, personID, err)
+ }
+ span.SetAttributes(attribute.String("comanage.person_id", personID))
+ return personID, composite, false, nil
}
- span.SetAttributes(attribute.String("comanage.person_id", personID))
- return personID, composite, false, nil
}
}
@@ -323,9 +348,48 @@ func (o *Orchestrator) lookupOrCreateCoPerson(ctx context.Context, user *models.
return r.Identifier, nil, true, nil
}
}
+ // COmanage's identifier-assignment plugin runs asynchronously, so
+ // POST /people sometimes returns an empty identifier
+ // list even though the CoPerson was created. Refetch by email with a short
+ // backoff and pull the identifier from the eventually consistent composite.
+ if user.Email != "" {
+ personID, composite, ok := o.waitForCreatedPersonID(user.Email, personIDType)
+ if ok {
+ span.SetAttributes(
+ attribute.String("comanage.person_id", personID),
+ attribute.Bool("comanage.created", true),
+ attribute.Bool("comanage.eventually_consistent", true),
+ )
+ return personID, composite, true, nil
+ }
+ }
return "", nil, false, fmt.Errorf("POST /people returned no %s identifier: %+v", personIDType, resp)
}
+// waitForCreatedPersonID polls findByEmailExact then the Identifiers list a
+// few times, since COmanage's identifier-assignment plugin runs asynchronously
+// after POST /people. Returns the assigned person_id once present.
+func (o *Orchestrator) waitForCreatedPersonID(email, personIDType string) (string, json.RawMessage, bool) {
+ delays := []time.Duration{300 * time.Millisecond, 700 * time.Millisecond, 1500 * time.Millisecond, 3 * time.Second}
+ for _, d := range delays {
+ time.Sleep(d)
+ coPersonID, err := o.findByEmailExact(email)
+ if err != nil || coPersonID == 0 {
+ continue
+ }
+ personID, err := o.c.FindIdentifierValueOnPerson(coPersonID, personIDType)
+ if err != nil || personID == "" {
+ continue
+ }
+ composite, err := o.c.GetPersonComposite(personID)
+ if err != nil {
+ continue
+ }
+ return personID, composite, true
+ }
+ return "", nil, false
+}
+
func buildCreatePersonBody(coID int, user *models.User) ([]byte, error) {
body := map[string]interface{}{
"CoPerson": map[string]interface{}{
diff --git a/connectors/COmanage/Identity-Provisioner/internal/operations/orchestrator_test.go b/connectors/COmanage/Identity-Provisioner/internal/operations/orchestrator_test.go
index 874801641..b6cfa89cb 100644
--- a/connectors/COmanage/Identity-Provisioner/internal/operations/orchestrator_test.go
+++ b/connectors/COmanage/Identity-Provisioner/internal/operations/orchestrator_test.go
@@ -150,6 +150,8 @@ func mockComanageServer(t *testing.T) *httptest.Server {
_, _ = io.WriteString(w, `{"ResponseType":"CoGroupMembers","Version":"1.0","CoGroupMembers":[]}`)
case r.Method == http.MethodPost && strings.HasSuffix(path, "/co_group_members.json"):
_, _ = io.WriteString(w, `{"ResponseType":"NewObject","Version":"1.0","ObjectType":"CoGroupMember","Id":"11"}`)
+ case r.Method == http.MethodGet && strings.HasSuffix(path, "/unix_cluster/unix_cluster_groups.json"):
+ _, _ = io.WriteString(w, `{"ResponseType":"UnixClusterGroups","Version":"1.0","UnixClusterGroups":[]}`)
case r.Method == http.MethodPost && strings.HasSuffix(path, "/unix_cluster/unix_cluster_groups.json"):
_, _ = io.WriteString(w, `{"ResponseType":"NewObject","Version":"1.0","ObjectType":"UnixClusterGroup","Id":"3"}`)
default:
@@ -199,7 +201,7 @@ func TestEnsurePOSIXAccount_EmitsComanageSpanTree(t *testing.T) {
"comanage.find_or_create_co_group",
"comanage.find_or_create_identifier",
"comanage.find_or_create_co_group_member",
- "comanage.create_unix_cluster_group",
+ "comanage.find_or_create_unix_cluster_group",
"comanage.get_person_composite",
"comanage.update_person",
}
diff --git a/dev-ops/compose/seeds/dev_portal_data.sql b/dev-ops/compose/seeds/dev_portal_data.sql
new file mode 100644
index 000000000..bd7f531c1
--- /dev/null
+++ b/dev-ops/compose/seeds/dev_portal_data.sql
@@ -0,0 +1,141 @@
+-- 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. Licensed
+-- under the Apache License, Version 2.0.
+--
+-- Dev-only seed: populates rows the AMIE protocol does not produce
+-- (resources, rates, mappings, usages, change requests, override). Apply
+-- AFTER the AMIE baseline scenario has run so the referenced cluster +
+-- allocation UUIDs exist. Safe to re-apply (idempotent).
+
+SET NAMES utf8mb4;
+SET
+time_zone = '+00:00';
+
+-- ---------------------------------------------------------------------------
+-- dev-admin direct privilege grants (bypasses the bootstrap super_admin →
+-- API-grant flow that would otherwise need a separate per-privilege POST).
+-- ---------------------------------------------------------------------------
+INSERT
+IGNORE INTO user_privileges (id, user_id, privilege, granted_by) VALUES
+ (UUID(), 'dev-admin', 'amie:read', 'dev-admin'),
+ (UUID(), 'dev-admin', 'amie:write', 'dev-admin'),
+ (UUID(), 'dev-admin', 'hpc:read', 'dev-admin'),
+ (UUID(), 'dev-admin', 'hpc:write', 'dev-admin'),
+ (UUID(), 'dev-admin', 'signer:read', 'dev-admin'),
+ (UUID(), 'dev-admin', 'signer:write', 'dev-admin');
+
+-- ---------------------------------------------------------------------------
+-- Resources (cluster-scoped resource catalog)
+-- ---------------------------------------------------------------------------
+INSERT INTO compute_allocation_resources (id, name, resource_type, resource_amount, compute_cluster_id)
+SELECT 'res-cpu', 'CPU Service Units', 'CPU_HOURS', 1000000, id
+FROM compute_clusters
+WHERE id = '00000000-0000-0000-0000-000000000001' ON DUPLICATE KEY
+UPDATE name =
+VALUES (name);
+
+INSERT INTO compute_allocation_resources (id, name, resource_type, resource_amount, compute_cluster_id)
+SELECT 'res-gpu', 'GPU Service Units', 'GPU_HOURS', 100000, id
+FROM compute_clusters
+WHERE id = '00000000-0000-0000-0000-000000000001' ON DUPLICATE KEY
+UPDATE name =
+VALUES (name);
+
+-- ---------------------------------------------------------------------------
+-- Resource → Allocation mappings (one CPU mapping per baseline allocation,
+-- and one GPU mapping on BL-001 so the UI shows multi-resource state).
+-- ---------------------------------------------------------------------------
+INSERT INTO compute_allocation_resource_mappings (id, compute_allocation_id, compute_allocation_resource_id,
+ resource_amount, resource_time)
+SELECT CONCAT('arm-cpu-', SUBSTRING(ca.id, 1, 8)), ca.id, 'res-cpu', 10000, 3600
+FROM compute_allocations ca
+WHERE ca.compute_cluster_id = '00000000-0000-0000-0000-000000000001' ON DUPLICATE KEY
+UPDATE resource_amount =
+VALUES (resource_amount);
+
+INSERT INTO compute_allocation_resource_mappings (id, compute_allocation_id, compute_allocation_resource_id,
+ resource_amount, resource_time)
+SELECT CONCAT('arm-gpu-', SUBSTRING(ca.id, 1, 8)), ca.id, 'res-gpu', 200, 3600
+FROM compute_allocations ca
+ JOIN projects p ON p.id = ca.project_id
+WHERE p.title = 'Baseline Project 1'
+ OR p.originated_id = 'BL-001' ON DUPLICATE KEY
+UPDATE resource_amount =
+VALUES (resource_amount);
+
+-- ---------------------------------------------------------------------------
+-- Resource rates
+-- ---------------------------------------------------------------------------
+INSERT INTO compute_allocation_resource_rates (id, compute_allocation_resource_id, rate, start_time, end_time)
+VALUES ('rate-cpu', 'res-cpu', 1.0, '2026-01-01 00:00:00', '2026-12-31 23:59:59'),
+ ('rate-gpu', 'res-gpu', 10.0, '2026-01-01 00:00:00', '2026-12-31 23:59:59') ON DUPLICATE KEY
+UPDATE rate =
+VALUES (rate);
+
+-- ---------------------------------------------------------------------------
+-- Usage record (one sample job per baseline allocation)
+-- ---------------------------------------------------------------------------
+INSERT INTO compute_allocation_usages
+(id, compute_allocation_id, used_raw_amount, used_su_amount, calculated_time, user_id, job_id,
+ compute_allocation_resource_id)
+SELECT CONCAT('usage-', SUBSTRING(ca.id, 1, 8)),
+ ca.id,
+ 250,
+ 250,
+ '2026-06-10 12:00:00',
+ u.id,
+ CONCAT('job-', SUBSTRING(ca.id, 1, 8)),
+ 'res-cpu'
+FROM compute_allocations ca
+ JOIN compute_cluster_users ccu ON ccu.compute_cluster_id = ca.compute_cluster_id
+ JOIN users u ON u.id = ccu.user_id
+WHERE ca.compute_cluster_id = '00000000-0000-0000-0000-000000000001' ON DUPLICATE KEY
+UPDATE used_raw_amount =
+VALUES (used_raw_amount);
+
+-- ---------------------------------------------------------------------------
+-- Change request + event (one PENDING request on the supplemented allocation)
+-- ---------------------------------------------------------------------------
+INSERT INTO compute_allocation_change_requests
+(id, compute_allocation_id, requested_su_amount, requested_status, reason, change_status, requester_id, approver_id,
+ timestamp)
+SELECT 'chreq-bl001',
+ ca.id,
+ 25000,
+ 'ACTIVE',
+ 'Additional SUs for end-of-year run',
+ 'PENDING',
+ 'dev-researcher',
+ '',
+ '2026-06-12 09:00:00'
+FROM compute_allocations ca
+ JOIN projects p ON p.id = ca.project_id
+WHERE p.title = 'Baseline Project 1'
+ OR p.originated_id = 'BL-001' LIMIT 1
+ON DUPLICATE KEY
+UPDATE reason =
+VALUES (reason);
+
+INSERT INTO compute_allocation_change_request_events
+(id, compute_allocation_change_request_id, event_type, description, timestamp)
+VALUES ('chreq-bl001-e1', 'chreq-bl001', 'CREATED', 'Change request submitted by researcher.', '2026-06-12 09:00:00'),
+ ('chreq-bl001-e2', 'chreq-bl001', 'COMMENTED', 'PI reviewed and queued for approval.',
+ '2026-06-13 11:30:00') ON DUPLICATE KEY
+UPDATE description =
+VALUES (description);
+
+-- ---------------------------------------------------------------------------
+-- Membership override (one example: cap a member's GPU resource amount)
+-- ---------------------------------------------------------------------------
+INSERT INTO compute_allocation_membership_resource_overrides
+(id, compute_allocation_membership_id, compute_allocation_resource_id, override_resource_amount, override_resource_time)
+SELECT CONCAT('over-', SUBSTRING(m.id, 1, 8)), m.id, 'res-gpu', 50, 3600
+FROM compute_allocation_memberships m
+ JOIN compute_allocations ca ON ca.id = m.compute_allocation_id
+ JOIN projects p ON p.id = ca.project_id
+WHERE p.title = 'Baseline Project 1'
+ OR p.originated_id = 'BL-001' LIMIT 1
+ON DUPLICATE KEY
+UPDATE override_resource_amount =
+VALUES (override_resource_amount);
diff --git a/dev-ops/local-amie/compose.yaml b/dev-ops/local-amie/compose.yaml
index 42f264064..e0b158081 100644
--- a/dev-ops/local-amie/compose.yaml
+++ b/dev-ops/local-amie/compose.yaml
@@ -50,7 +50,7 @@ services:
ports:
- "8181:8180"
healthcheck:
- test: [ "CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8180/packets/TESTSITE').read()" ]
+ test: [ "CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8180/stats').read()" ]
interval: 2s
timeout: 5s
retries: 30
diff --git a/internal/db/migrations/000013_membership_role.down.sql b/internal/db/migrations/000013_membership_role.down.sql
new file mode 100644
index 000000000..28c87bac6
--- /dev/null
+++ b/internal/db/migrations/000013_membership_role.down.sql
@@ -0,0 +1,20 @@
+-- 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.
+
+ALTER TABLE compute_allocation_memberships
+ DROP KEY idx_compute_allocation_memberships_role,
+ DROP COLUMN role;
diff --git a/internal/db/migrations/000013_membership_role.up.sql b/internal/db/migrations/000013_membership_role.up.sql
new file mode 100644
index 000000000..3df06618f
--- /dev/null
+++ b/internal/db/migrations/000013_membership_role.up.sql
@@ -0,0 +1,23 @@
+-- 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.
+
+-- Persisted role of a user on a compute allocation membership. Values mirror
+-- the AMIE-protocol role enum (PI / CO_PI / ALLOCATION_MANAGER / MEMBER);
+-- non-AMIE callers default to MEMBER.
+ALTER TABLE compute_allocation_memberships
+ ADD COLUMN role VARCHAR(32) NOT NULL DEFAULT 'MEMBER' AFTER membership_status,
+ ADD KEY idx_compute_allocation_memberships_role (role);
diff --git a/internal/server/responses.go b/internal/server/responses.go
new file mode 100644
index 000000000..c53acebaf
--- /dev/null
+++ b/internal/server/responses.go
@@ -0,0 +1,92 @@
+// 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 server
+
+import (
+ "time"
+
+ "github.com/apache/airavata-custos/pkg/models"
+)
+
+// ProjectResponse is the API response shape for a project. It embeds the core
+// Project entity and adds display fields the portal renders so the entity
+// itself stays free of presentation concerns.
+type ProjectResponse struct {
+ models.Project
+ ProjectPIDisplayName string `json:"project_pi_display_name,omitempty"`
+ ProjectPIEmail string `json:"project_pi_email,omitempty"`
+}
+
+// ProjectListResponse is the paginated list envelope for projects.
+type ProjectListResponse struct {
+ Items []ProjectResponse `json:"items"`
+ Total int `json:"total"`
+}
+
+// ProjectMemberAllocationRef carries the (allocation, role) the user holds on
+// one of the project's allocations.
+type ProjectMemberAllocationRef struct {
+ ID string `json:"id"`
+ Name string `json:"name"`
+ Role string `json:"role"`
+}
+
+// ProjectMemberResponse is one row in the project members tab. Role is the
+// strongest role the user holds across the project's allocations; the raw
+// per-allocation roles live in Allocations.
+type ProjectMemberResponse struct {
+ ID string `json:"id"`
+ ProjectID string `json:"project_id"`
+ UserID string `json:"user_id"`
+ Email string `json:"email"`
+ DisplayName string `json:"display_name"`
+ Role string `json:"role"`
+ Status string `json:"status"`
+ AddedTime time.Time `json:"added_time"`
+ Allocations []ProjectMemberAllocationRef `json:"allocations"`
+}
+
+// AllocationMembershipResponse embeds the persisted membership and surfaces
+// the joined user display fields without putting them on the core entity.
+type AllocationMembershipResponse struct {
+ models.ComputeAllocationMembership
+ DisplayName string `json:"display_name,omitempty"`
+ Email string `json:"email,omitempty"`
+}
+
+// ComputeAllocationListResponse is the paginated list envelope for compute
+// allocations.
+type ComputeAllocationListResponse struct {
+ Items []models.ComputeAllocation `json:"items"`
+ Total int `json:"total"`
+}
+
+// AllocationSUTotalResponse is the response for total SUs consumed on an
+// allocation.
+type AllocationSUTotalResponse struct {
+ ComputeAllocationID string `json:"compute_allocation_id"`
+ TotalSUAmount int64 `json:"total_su_amount"`
+}
+
+// UserAllocationSUTotalResponse is the response for SUs consumed by one user
+// on one allocation.
+type UserAllocationSUTotalResponse struct {
+ ComputeAllocationID string `json:"compute_allocation_id"`
+ UserID string `json:"user_id"`
+ TotalSUAmount int64 `json:"total_su_amount"`
+}
diff --git a/internal/server/server.go b/internal/server/server.go
index 9dca02b27..fd8e17001 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -23,6 +23,7 @@ import (
"errors"
"log/slog"
"net/http"
+ "strconv"
"strings"
"time"
@@ -78,9 +79,11 @@ func (s *Server) routes() {
s.mux.HandleFunc("PUT /users/{id}/status", s.updateUserStatus)
s.mux.HandleFunc("POST /users/merge", s.mergeUsers)
+ s.mux.HandleFunc("GET /projects", s.listProjects)
s.mux.HandleFunc("POST /projects", s.createProject)
s.mux.HandleFunc("GET /projects/{id}", s.getProject)
s.mux.HandleFunc("PUT /projects/{id}/status", s.updateProjectStatus)
+ s.mux.HandleFunc("GET /projects/{id}/members", s.listProjectMembers)
s.mux.HandleFunc("POST /compute-clusters", s.createComputeCluster)
s.mux.HandleFunc("GET /compute-clusters", s.listComputeClusters)
@@ -94,6 +97,7 @@ func (s *Server) routes() {
s.mux.HandleFunc("GET /compute-clusters/{id}/users/{userId}", s.getComputeClusterUserByPair)
s.mux.HandleFunc("GET /users/{id}/compute-cluster-users", s.listComputeClusterUsersByUser)
+ s.mux.HandleFunc("GET /compute-allocations", s.listComputeAllocations)
s.mux.HandleFunc("POST /compute-allocations", s.createComputeAllocation)
s.mux.HandleFunc("GET /compute-allocations/{id}", s.getComputeAllocation)
@@ -118,6 +122,7 @@ func (s *Server) routes() {
s.mux.HandleFunc("GET /compute-allocations/{id}/diffs", s.listDiffsForAllocation)
s.mux.HandleFunc("GET /compute-allocations/{id}/diffs/latest", s.getLatestDiffForAllocation)
+ s.mux.HandleFunc("GET /compute-allocation-change-requests", s.listChangeRequests)
s.mux.HandleFunc("POST /compute-allocation-change-requests", s.createComputeAllocationChangeRequest)
s.mux.HandleFunc("GET /compute-allocation-change-requests/{id}", s.getComputeAllocationChangeRequest)
s.mux.HandleFunc("PUT /compute-allocation-change-requests/{id}", s.updateComputeAllocationChangeRequest)
@@ -299,16 +304,27 @@ func (s *Server) createProject(w http.ResponseWriter, r *http.Request) {
// @Security CustosUserHeader
// @Produce json
// @Param id path string true "Project ID"
-// @Success 200 {object} models.Project
+// @Success 200 {object} ProjectResponse
// @Failure 404 {object} object{error=string}
// @Router /projects/{id} [get]
func (s *Server) getProject(w http.ResponseWriter, r *http.Request) {
- p, err := s.svc.GetProject(r.Context(), r.PathValue("id"))
+ p, err := s.svc.GetProjectWithPI(r.Context(), r.PathValue("id"))
if err != nil {
writeServiceError(w, err)
return
}
- writeJSON(w, http.StatusOK, p)
+ writeJSON(w, http.StatusOK, projectResponseFrom(p))
+}
+
+// projectResponseFrom builds the API response shape from a JOIN-fetched row.
+func projectResponseFrom(p *store.ProjectWithPI) ProjectResponse {
+ v := ProjectResponse{Project: p.Project, ProjectPIEmail: p.PIEmail}
+ if full := strings.TrimSpace(p.PIFirstName + " " + p.PILastName); full != "" {
+ v.ProjectPIDisplayName = full
+ } else if p.PIEmail != "" {
+ v.ProjectPIDisplayName = p.PIEmail
+ }
+ return v
}
// @Summary Create a compute cluster
@@ -1206,7 +1222,7 @@ func (s *Server) deleteComputeAllocationMembership(w http.ResponseWriter, r *htt
// @Security CustosUserHeader
// @Produce json
// @Param id path string true "Compute allocation ID"
-// @Success 200 {array} models.ComputeAllocationMembership
+// @Success 200 {array} AllocationMembershipResponse
// @Failure 404 {object} object{error=string}
// @Router /compute-allocations/{id}/memberships [get]
func (s *Server) listMembersForAllocation(w http.ResponseWriter, r *http.Request) {
@@ -1215,7 +1231,15 @@ func (s *Server) listMembersForAllocation(w http.ResponseWriter, r *http.Request
writeServiceError(w, err)
return
}
- writeJSON(w, http.StatusOK, rows)
+ out := make([]AllocationMembershipResponse, 0, len(rows))
+ for _, m := range rows {
+ out = append(out, AllocationMembershipResponse{
+ ComputeAllocationMembership: m.ComputeAllocationMembership,
+ DisplayName: m.DisplayName,
+ Email: m.Email,
+ })
+ }
+ writeJSON(w, http.StatusOK, out)
}
// @Summary List a user's compute allocation memberships
@@ -1444,7 +1468,7 @@ func (s *Server) listOverridesForResource(w http.ResponseWriter, r *http.Request
// @Security CustosUserHeader
// @Produce json
// @Param id path string true "Compute allocation ID"
-// @Success 200 {object} object{compute_allocation_id=string,total_su_amount=integer}
+// @Success 200 {object} AllocationSUTotalResponse
// @Failure 404 {object} object{error=string}
// @Router /compute-allocations/{id}/usages/total [get]
func (s *Server) getTotalSUUsageForAllocation(w http.ResponseWriter, r *http.Request) {
@@ -1453,9 +1477,9 @@ func (s *Server) getTotalSUUsageForAllocation(w http.ResponseWriter, r *http.Req
writeServiceError(w, err)
return
}
- writeJSON(w, http.StatusOK, map[string]any{
- "compute_allocation_id": r.PathValue("id"),
- "total_su_amount": total,
+ writeJSON(w, http.StatusOK, AllocationSUTotalResponse{
+ ComputeAllocationID: r.PathValue("id"),
+ TotalSUAmount: total,
})
}
@@ -1465,7 +1489,7 @@ func (s *Server) getTotalSUUsageForAllocation(w http.ResponseWriter, r *http.Req
// @Produce json
// @Param id path string true "Compute allocation ID"
// @Param userId path string true "User ID"
-// @Success 200 {object} object{compute_allocation_id=string,user_id=string,total_su_amount=integer}
+// @Success 200 {object} UserAllocationSUTotalResponse
// @Failure 404 {object} object{error=string}
// @Router /compute-allocations/{id}/users/{userId}/usages/total [get]
func (s *Server) getTotalSUUsageForUserInAllocation(w http.ResponseWriter, r *http.Request) {
@@ -1476,10 +1500,10 @@ func (s *Server) getTotalSUUsageForUserInAllocation(w http.ResponseWriter, r *ht
writeServiceError(w, err)
return
}
- writeJSON(w, http.StatusOK, map[string]any{
- "compute_allocation_id": allocationID,
- "user_id": userID,
- "total_su_amount": total,
+ writeJSON(w, http.StatusOK, UserAllocationSUTotalResponse{
+ ComputeAllocationID: allocationID,
+ UserID: userID,
+ TotalSUAmount: total,
})
}
@@ -1754,3 +1778,178 @@ func writeServiceError(w http.ResponseWriter, err error) {
writeError(w, http.StatusInternalServerError, errors.New(strings.TrimSpace("internal server error")))
}
}
+
+// @Summary List projects (filtered + paginated, PI joined)
+// @Tags Projects
+// @Security CustosUserHeader
+// @Produce json
+// @Param pi_id query string false "Filter by PI user ID"
+// @Param status query string false "Filter by status"
+// @Param q query string false "Search title / originated_id"
+// @Param limit query integer false "Page size"
+// @Param offset query integer false "Page offset"
+// @Success 200 {object} ProjectListResponse
+// @Router /projects [get]
+func (s *Server) listProjects(w http.ResponseWriter, r *http.Request) {
+ q := r.URL.Query()
+ f := store.ProjectListFilter{
+ PIID: q.Get("pi_id"),
+ Status: q.Get("status"),
+ Query: q.Get("q"),
+ Limit: atoiOr(q.Get("limit"), 50),
+ Offset: atoiOr(q.Get("offset"), 0),
+ }
+ rows, total, err := s.svc.ListProjectsWithPI(r.Context(), f)
+ if err != nil {
+ writeServiceError(w, err)
+ return
+ }
+ items := make([]ProjectResponse, 0, len(rows))
+ for i := range rows {
+ items = append(items, projectResponseFrom(&rows[i]))
+ }
+ writeJSON(w, http.StatusOK, ProjectListResponse{Items: items, Total: total})
+}
+
+// @Summary List project members (one row per distinct user, with allocations)
+// @Tags Projects
+// @Security CustosUserHeader
+// @Produce json
+// @Param id path string true "Project ID"
+// @Success 200 {array} ProjectMemberResponse
+// @Failure 404 {object} object{error=string}
+// @Router /projects/{id}/members [get]
+func (s *Server) listProjectMembers(w http.ResponseWriter, r *http.Request) {
+ projectID := r.PathValue("id")
+ rows, err := s.svc.ListMembersForProject(r.Context(), projectID)
+ if err != nil {
+ writeServiceError(w, err)
+ return
+ }
+
+ type aggregate struct {
+ base store.MembershipWithUser
+ allocations []ProjectMemberAllocationRef
+ bestRank int
+ }
+ byUser := map[string]*aggregate{}
+ order := []string{}
+ for _, m := range rows {
+ agg, ok := byUser[m.UserID]
+ if !ok {
+ agg = &aggregate{base: m, bestRank: roleRank(m.Role)}
+ byUser[m.UserID] = agg
+ order = append(order, m.UserID)
+ } else if r := roleRank(m.Role); r > agg.bestRank {
+ agg.base = m
+ agg.bestRank = r
+ }
+ agg.allocations = append(agg.allocations, ProjectMemberAllocationRef{
+ ID: m.ComputeAllocationID,
+ Name: m.AllocationName,
+ Role: m.Role,
+ })
+ }
+
+ out := make([]ProjectMemberResponse, 0, len(order))
+ for _, uid := range order {
+ agg := byUser[uid]
+ out = append(out, ProjectMemberResponse{
+ ID: agg.base.ID,
+ ProjectID: projectID,
+ UserID: agg.base.UserID,
+ Email: agg.base.Email,
+ DisplayName: agg.base.DisplayName,
+ Role: projectRole(agg.base.Role),
+ Status: string(agg.base.MembershipStatus),
+ AddedTime: agg.base.StartTime.UTC(),
+ Allocations: agg.allocations,
+ })
+ }
+ writeJSON(w, http.StatusOK, out)
+}
+
+// projectRole collapses the four allocation-level role values to the three
+// the project-members surface needs (ALLOCATION_MANAGER → MEMBER).
+func projectRole(r string) string {
+ switch r {
+ case "PI", "CO_PI":
+ return r
+ default:
+ return "MEMBER"
+ }
+}
+
+// roleRank ranks allocation roles for "strongest role across allocations".
+func roleRank(r string) int {
+ switch r {
+ case "PI":
+ return 4
+ case "CO_PI":
+ return 3
+ case "ALLOCATION_MANAGER":
+ return 2
+ case "MEMBER":
+ return 1
+ }
+ return 0
+}
+
+// @Summary List compute allocations (filtered + paginated)
+// @Tags Compute Allocations
+// @Security CustosUserHeader
+// @Produce json
+// @Param project_id query string false "Filter by project ID"
+// @Param status query string false "Filter by status"
+// @Param q query string false "Search name"
+// @Param limit query integer false "Page size"
+// @Param offset query integer false "Page offset"
+// @Success 200 {object} ComputeAllocationListResponse
+// @Router /compute-allocations [get]
+func (s *Server) listComputeAllocations(w http.ResponseWriter, r *http.Request) {
+ q := r.URL.Query()
+ f := store.AllocationListFilter{
+ ProjectID: q.Get("project_id"),
+ Status: q.Get("status"),
+ Query: q.Get("q"),
+ Limit: atoiOr(q.Get("limit"), 50),
+ Offset: atoiOr(q.Get("offset"), 0),
+ }
+ rows, total, err := s.svc.ListComputeAllocations(r.Context(), f)
+ if err != nil {
+ writeServiceError(w, err)
+ return
+ }
+ if rows == nil {
+ rows = []models.ComputeAllocation{}
+ }
+ writeJSON(w, http.StatusOK, ComputeAllocationListResponse{Items: rows, Total: total})
+}
+
+func (s *Server) listChangeRequests(w http.ResponseWriter, r *http.Request) {
+ q := r.URL.Query()
+ f := store.ChangeRequestListFilter{
+ Status: q.Get("status"),
+ Limit: atoiOr(q.Get("limit"), 50),
+ }
+ rows, err := s.svc.ListChangeRequests(r.Context(), f)
+ if err != nil {
+ writeServiceError(w, err)
+ return
+ }
+ if rows == nil {
+ rows = []models.ComputeAllocationChangeRequest{}
+ }
+ writeJSON(w, http.StatusOK, rows)
+}
+
+func atoiOr(s string, def int) int {
+ if s == "" {
+ return def
+ }
+ n, err := strconv.Atoi(s)
+ if err != nil {
+ return def
+ }
+ return n
+}
diff --git a/internal/store/compute_allocation_change_request_store.go b/internal/store/compute_allocation_change_request_store.go
index b0b87fe8f..bd2010778 100644
--- a/internal/store/compute_allocation_change_request_store.go
+++ b/internal/store/compute_allocation_change_request_store.go
@@ -107,3 +107,27 @@ func (s *mysqlComputeAllocationChangeRequestStore) Delete(ctx context.Context, t
_, err := tx.ExecContext(ctx, `DELETE FROM compute_allocation_change_requests WHERE id = ?`, id)
return err
}
+
+func (s *mysqlComputeAllocationChangeRequestStore) List(ctx context.Context, f ChangeRequestListFilter) ([]models.ComputeAllocationChangeRequest, error) {
+ limit := f.Limit
+ if limit <= 0 {
+ limit = 50
+ }
+ if limit > 200 {
+ limit = 200
+ }
+ if f.Status != "" {
+ var rows []models.ComputeAllocationChangeRequest
+ err := s.db.SelectContext(ctx, &rows,
+ `SELECT `+computeAllocationChangeRequestColumns+
+ ` FROM compute_allocation_change_requests WHERE change_status = ?`+
+ ` ORDER BY timestamp DESC LIMIT ?`, f.Status, limit)
+ return rows, err
+ }
+ var rows []models.ComputeAllocationChangeRequest
+ err := s.db.SelectContext(ctx, &rows,
+ `SELECT `+computeAllocationChangeRequestColumns+
+ ` FROM compute_allocation_change_requests`+
+ ` ORDER BY timestamp DESC LIMIT ?`, limit)
+ return rows, err
+}
diff --git a/internal/store/compute_allocation_membership_store.go b/internal/store/compute_allocation_membership_store.go
index e79c842fb..6feb946eb 100644
--- a/internal/store/compute_allocation_membership_store.go
+++ b/internal/store/compute_allocation_membership_store.go
@@ -27,7 +27,17 @@ import (
"github.com/apache/airavata-custos/pkg/models"
)
-const computeAllocationMembershipColumns = "id, compute_allocation_id, user_id, start_time, end_time, membership_status"
+const computeAllocationMembershipColumns = "id, compute_allocation_id, user_id, start_time, end_time, membership_status, role"
+
+// MembershipWithUser is the result shape of the join-based list methods. It
+// keeps the joined user + allocation fields off the core
+// ComputeAllocationMembership entity.
+type MembershipWithUser struct {
+ models.ComputeAllocationMembership
+ DisplayName string
+ Email string
+ AllocationName string
+}
type mysqlComputeAllocationMembershipStore struct {
db *sqlx.DB
@@ -94,24 +104,33 @@ func (s *mysqlComputeAllocationMembershipStore) FindByUser(ctx context.Context,
}
func (s *mysqlComputeAllocationMembershipStore) Create(ctx context.Context, tx *sql.Tx, m *models.ComputeAllocationMembership) error {
+ role := m.Role
+ if role == "" {
+ role = "MEMBER"
+ }
_, err := tx.ExecContext(ctx,
`INSERT INTO compute_allocation_memberships
- (id, compute_allocation_id, user_id, start_time, end_time, membership_status)
- VALUES (?, ?, ?, ?, ?, ?)`,
- m.ID, m.ComputeAllocationID, m.UserID, m.StartTime, m.EndTime, string(m.MembershipStatus))
+ (id, compute_allocation_id, user_id, start_time, end_time, membership_status, role)
+ VALUES (?, ?, ?, ?, ?, ?, ?)`,
+ m.ID, m.ComputeAllocationID, m.UserID, m.StartTime, m.EndTime, string(m.MembershipStatus), role)
return err
}
func (s *mysqlComputeAllocationMembershipStore) Update(ctx context.Context, tx *sql.Tx, m *models.ComputeAllocationMembership) error {
+ role := m.Role
+ if role == "" {
+ role = "MEMBER"
+ }
_, err := tx.ExecContext(ctx,
`UPDATE compute_allocation_memberships
SET compute_allocation_id = ?,
user_id = ?,
start_time = ?,
end_time = ?,
- membership_status = ?
+ membership_status = ?,
+ role = ?
WHERE id = ?`,
- m.ComputeAllocationID, m.UserID, m.StartTime, m.EndTime, string(m.MembershipStatus), m.ID)
+ m.ComputeAllocationID, m.UserID, m.StartTime, m.EndTime, string(m.MembershipStatus), role, m.ID)
return err
}
@@ -137,3 +156,88 @@ func (s *mysqlComputeAllocationMembershipStore) Delete(ctx context.Context, tx *
_, err := tx.ExecContext(ctx, `DELETE FROM compute_allocation_memberships WHERE id = ?`, id)
return err
}
+
+// FindByAllocationWithUser returns memberships for an allocation joined with
+// user so each row carries display_name and email. Display fields stay on
+// MembershipWithUser, not on the core entity.
+func (s *mysqlComputeAllocationMembershipStore) FindByAllocationWithUser(ctx context.Context, allocationID string) ([]MembershipWithUser, error) {
+ type row struct {
+ models.ComputeAllocationMembership
+ FirstName string `db:"first_name"`
+ LastName string `db:"last_name"`
+ UserEmail string `db:"user_email"`
+ }
+ var rows []row
+ err := s.db.SelectContext(ctx, &rows,
+ `SELECT m.id, m.compute_allocation_id, m.user_id, m.start_time, m.end_time,
+ m.membership_status, m.role,
+ u.first_name, u.last_name, u.email AS user_email
+ FROM compute_allocation_memberships m
+ JOIN users u ON u.id = m.user_id
+ WHERE m.compute_allocation_id = ?
+ ORDER BY m.start_time`, allocationID)
+ if err != nil {
+ return nil, err
+ }
+ out := make([]MembershipWithUser, 0, len(rows))
+ for _, r := range rows {
+ out = append(out, MembershipWithUser{
+ ComputeAllocationMembership: r.ComputeAllocationMembership,
+ DisplayName: displayName(r.FirstName, r.LastName, r.UserEmail),
+ Email: r.UserEmail,
+ })
+ }
+ return out, nil
+}
+
+// FindByProjectWithUser returns every membership across every allocation in
+// the project, joined with the user and the owning allocation name. Caller
+// aggregates per-user (the project-members view dedups + collapses role).
+func (s *mysqlComputeAllocationMembershipStore) FindByProjectWithUser(ctx context.Context, projectID string) ([]MembershipWithUser, error) {
+ type row struct {
+ models.ComputeAllocationMembership
+ FirstName string `db:"first_name"`
+ LastName string `db:"last_name"`
+ UserEmail string `db:"user_email"`
+ AllocationName string `db:"allocation_name"`
+ }
+ var rows []row
+ err := s.db.SelectContext(ctx, &rows,
+ `SELECT m.id, m.compute_allocation_id, m.user_id, m.start_time, m.end_time,
+ m.membership_status, m.role,
+ u.first_name, u.last_name, u.email AS user_email,
+ ca.name AS allocation_name
+ FROM compute_allocation_memberships m
+ JOIN compute_allocations ca ON ca.id = m.compute_allocation_id
+ JOIN users u ON u.id = m.user_id
+ WHERE ca.project_id = ?
+ ORDER BY u.email, ca.name`, projectID)
+ if err != nil {
+ return nil, err
+ }
+ out := make([]MembershipWithUser, 0, len(rows))
+ for _, r := range rows {
+ out = append(out, MembershipWithUser{
+ ComputeAllocationMembership: r.ComputeAllocationMembership,
+ DisplayName: displayName(r.FirstName, r.LastName, r.UserEmail),
+ Email: r.UserEmail,
+ AllocationName: r.AllocationName,
+ })
+ }
+ return out, nil
+}
+
+func displayName(first, last, email string) string {
+ full := ""
+ if first != "" || last != "" {
+ full = first
+ if first != "" && last != "" {
+ full += " "
+ }
+ full += last
+ }
+ if full == "" {
+ return email
+ }
+ return full
+}
diff --git a/internal/store/compute_allocation_store.go b/internal/store/compute_allocation_store.go
index 9bfc5c922..714f88261 100644
--- a/internal/store/compute_allocation_store.go
+++ b/internal/store/compute_allocation_store.go
@@ -21,6 +21,7 @@ import (
"context"
"database/sql"
"errors"
+ "strings"
"github.com/jmoiron/sqlx"
@@ -94,3 +95,47 @@ func (s *mysqlComputeAllocationStore) Delete(ctx context.Context, tx *sql.Tx, id
_, err := tx.ExecContext(ctx, `DELETE FROM compute_allocations WHERE id = ?`, id)
return err
}
+
+func (s *mysqlComputeAllocationStore) List(ctx context.Context, f AllocationListFilter) ([]models.ComputeAllocation, int, error) {
+ where := []string{}
+ args := []any{}
+ if f.ProjectID != "" {
+ where = append(where, `project_id = ?`)
+ args = append(args, f.ProjectID)
+ }
+ if f.Status != "" {
+ where = append(where, `status = ?`)
+ args = append(args, f.Status)
+ }
+ if f.Query != "" {
+ where = append(where, `name LIKE ?`)
+ args = append(args, "%"+f.Query+"%")
+ }
+ clause := ""
+ if len(where) > 0 {
+ clause = " WHERE " + strings.Join(where, " AND ")
+ }
+ var total int
+ if err := s.db.GetContext(ctx, &total, `SELECT COUNT(*) FROM compute_allocations`+clause, args...); err != nil {
+ return nil, 0, err
+ }
+ limit := f.Limit
+ if limit <= 0 {
+ limit = 50
+ }
+ if limit > 200 {
+ limit = 200
+ }
+ offset := f.Offset
+ if offset < 0 {
+ offset = 0
+ }
+ query := `SELECT ` + computeAllocationColumns + ` FROM compute_allocations` + clause +
+ ` ORDER BY start_time DESC LIMIT ? OFFSET ?`
+ args = append(args, limit, offset)
+ var rows []models.ComputeAllocation
+ if err := s.db.SelectContext(ctx, &rows, query, args...); err != nil {
+ return nil, 0, err
+ }
+ return rows, total, nil
+}
diff --git a/internal/store/project_store.go b/internal/store/project_store.go
index 13fe71fbd..2babb9bf9 100644
--- a/internal/store/project_store.go
+++ b/internal/store/project_store.go
@@ -21,6 +21,7 @@ import (
"context"
"database/sql"
"errors"
+ "strings"
"github.com/jmoiron/sqlx"
@@ -38,6 +39,38 @@ func NewProjectStore(db *sqlx.DB) ProjectStore {
const projectColumns = `id, originated_id, title, origination, project_pi_id, status, created_time`
+// ProjectWithPI is FindByIDWithPI / ListWithPI row shape: the project plus
+// the joined PI's display fields. Kept here so handlers can render the
+// portal-facing payload from a single SQL round trip.
+type ProjectWithPI struct {
+ models.Project
+ PIFirstName string `db:"pi_first_name"`
+ PILastName string `db:"pi_last_name"`
+ PIEmail string `db:"pi_email"`
+}
+
+// projectWithPISelect joins users so a single query returns everything the
+// portal needs to render a project row.
+const projectWithPISelect = `SELECT p.id, p.originated_id, p.title, p.origination, p.project_pi_id,
+ p.status, p.created_time,
+ u.first_name AS pi_first_name, u.last_name AS pi_last_name, u.email AS pi_email
+ FROM projects p
+ LEFT JOIN users u ON u.id = p.project_pi_id`
+
+// FindByIDWithPI returns the project joined with its PI's display fields, or
+// nil if no project matches.
+func (s *mysqlProjectStore) FindByIDWithPI(ctx context.Context, id string) (*ProjectWithPI, error) {
+ var p ProjectWithPI
+ err := s.db.GetContext(ctx, &p, projectWithPISelect+` WHERE p.id = ?`, id)
+ if err != nil {
+ if errors.Is(err, sql.ErrNoRows) {
+ return nil, nil
+ }
+ return nil, err
+ }
+ return &p, nil
+}
+
func (s *mysqlProjectStore) FindByID(ctx context.Context, id string) (*models.Project, error) {
var p models.Project
err := s.db.GetContext(ctx, &p,
@@ -108,3 +141,94 @@ func (s *mysqlProjectStore) Delete(ctx context.Context, tx *sql.Tx, id string) e
_, err := tx.ExecContext(ctx, `DELETE FROM projects WHERE id = ?`, id)
return err
}
+
+func (s *mysqlProjectStore) List(ctx context.Context, f ProjectListFilter) ([]models.Project, int, error) {
+ where := []string{}
+ args := []any{}
+ if f.PIID != "" {
+ where = append(where, `project_pi_id = ?`)
+ args = append(args, f.PIID)
+ }
+ if f.Status != "" {
+ where = append(where, `status = ?`)
+ args = append(args, f.Status)
+ }
+ if f.Query != "" {
+ where = append(where, `(title LIKE ? OR originated_id LIKE ?)`)
+ q := "%" + f.Query + "%"
+ args = append(args, q, q)
+ }
+ clause := ""
+ if len(where) > 0 {
+ clause = " WHERE " + strings.Join(where, " AND ")
+ }
+ var total int
+ if err := s.db.GetContext(ctx, &total, `SELECT COUNT(*) FROM projects`+clause, args...); err != nil {
+ return nil, 0, err
+ }
+ limit := f.Limit
+ if limit <= 0 {
+ limit = 50
+ }
+ if limit > 200 {
+ limit = 200
+ }
+ offset := f.Offset
+ if offset < 0 {
+ offset = 0
+ }
+ query := `SELECT ` + projectColumns + ` FROM projects` + clause +
+ ` ORDER BY created_time DESC LIMIT ? OFFSET ?`
+ args = append(args, limit, offset)
+ var rows []models.Project
+ if err := s.db.SelectContext(ctx, &rows, query, args...); err != nil {
+ return nil, 0, err
+ }
+ return rows, total, nil
+}
+
+// ListWithPI is List joined with the PI user. Replaces per-row GetUser calls
+// the handler used to fan out across the result set.
+func (s *mysqlProjectStore) ListWithPI(ctx context.Context, f ProjectListFilter) ([]ProjectWithPI, int, error) {
+ where := []string{}
+ args := []any{}
+ if f.PIID != "" {
+ where = append(where, `p.project_pi_id = ?`)
+ args = append(args, f.PIID)
+ }
+ if f.Status != "" {
+ where = append(where, `p.status = ?`)
+ args = append(args, f.Status)
+ }
+ if f.Query != "" {
+ where = append(where, `(p.title LIKE ? OR p.originated_id LIKE ?)`)
+ q := "%" + f.Query + "%"
+ args = append(args, q, q)
+ }
+ clause := ""
+ if len(where) > 0 {
+ clause = " WHERE " + strings.Join(where, " AND ")
+ }
+ var total int
+ if err := s.db.GetContext(ctx, &total, `SELECT COUNT(*) FROM projects p`+clause, args...); err != nil {
+ return nil, 0, err
+ }
+ limit := f.Limit
+ if limit <= 0 {
+ limit = 50
+ }
+ if limit > 200 {
+ limit = 200
+ }
+ offset := f.Offset
+ if offset < 0 {
+ offset = 0
+ }
+ query := projectWithPISelect + clause + ` ORDER BY p.created_time DESC LIMIT ? OFFSET ?`
+ args = append(args, limit, offset)
+ var rows []ProjectWithPI
+ if err := s.db.SelectContext(ctx, &rows, query, args...); err != nil {
+ return nil, 0, err
+ }
+ return rows, total, nil
+}
diff --git a/internal/store/store.go b/internal/store/store.go
index 385bfb927..22a459a76 100644
--- a/internal/store/store.go
+++ b/internal/store/store.go
@@ -137,6 +137,24 @@ type ProjectStore interface {
ReassignPI(ctx context.Context, tx *sql.Tx, fromUserID, toUserID string) error
// Delete removes a project by ID within the provided transaction.
Delete(ctx context.Context, tx *sql.Tx, id string) error
+ // List returns a paginated, filtered slice of projects plus the total
+ // count matching the filter (ignoring limit/offset).
+ List(ctx context.Context, f ProjectListFilter) ([]models.Project, int, error)
+ // FindByIDWithPI is FindByID joined with the PI user, so a single query
+ // returns everything the portal needs to render a project header.
+ FindByIDWithPI(ctx context.Context, id string) (*ProjectWithPI, error)
+ // ListWithPI is List joined with the PI user, replacing the per-row
+ // GetUser fan-out the handler would otherwise need.
+ ListWithPI(ctx context.Context, f ProjectListFilter) ([]ProjectWithPI, int, error)
+}
+
+// ProjectListFilter selects which projects ProjectStore.List returns.
+type ProjectListFilter struct {
+ PIID string
+ Status string
+ Query string
+ Limit int
+ Offset int
}
// ComputeAllocationStore defines persistence operations for compute allocations.
@@ -153,6 +171,18 @@ type ComputeAllocationStore interface {
Update(ctx context.Context, tx *sql.Tx, a *models.ComputeAllocation) error
// Delete removes an allocation by ID within the provided transaction.
Delete(ctx context.Context, tx *sql.Tx, id string) error
+ // List returns a paginated, filtered slice of allocations plus the total
+ // count matching the filter (ignoring limit/offset).
+ List(ctx context.Context, f AllocationListFilter) ([]models.ComputeAllocation, int, error)
+}
+
+// AllocationListFilter selects which allocations ComputeAllocationStore.List returns.
+type AllocationListFilter struct {
+ ProjectID string
+ Status string
+ Query string
+ Limit int
+ Offset int
}
// ComputeAllocationResourceStore defines persistence operations for compute
@@ -251,6 +281,15 @@ type ComputeAllocationChangeRequestStore interface {
Update(ctx context.Context, tx *sql.Tx, c *models.ComputeAllocationChangeRequest) error
// Delete removes a change request by ID within the provided transaction.
Delete(ctx context.Context, tx *sql.Tx, id string) error
+ // List returns change requests filtered by the supplied criteria.
+ List(ctx context.Context, f ChangeRequestListFilter) ([]models.ComputeAllocationChangeRequest, error)
+}
+
+// ChangeRequestListFilter selects which change request
+// ComputeAllocationChangeRequestStore.List returns.
+type ChangeRequestListFilter struct {
+ Status string
+ Limit int
}
// ComputeAllocationChangeRequestEventStore defines persistence operations
@@ -285,6 +324,14 @@ type ComputeAllocationMembershipStore interface {
// FindByUser returns every membership held by the given user, ordered by
// start_time ascending.
FindByUser(ctx context.Context, userID string) ([]models.ComputeAllocationMembership, error)
+ // FindByAllocationWithUser is FindByAllocation joined with user so each
+ // row carries display_name and email. Display fields live on
+ // MembershipWithUser, not on the core entity.
+ FindByAllocationWithUser(ctx context.Context, allocationID string) ([]MembershipWithUser, error)
+ // FindByProjectWithUser returns memberships across every allocation in
+ // the project joined with users and allocation name. The caller dedups
+ // per user and collapses role for the project-level view.
+ FindByProjectWithUser(ctx context.Context, projectID string) ([]MembershipWithUser, error)
// Create inserts a new membership within the provided transaction.
Create(ctx context.Context, tx *sql.Tx, m *models.ComputeAllocationMembership) error
// Update replaces mutable fields of an existing membership within the provided transaction.
diff --git a/pkg/models/allocation.go b/pkg/models/allocation.go
index b372d2557..f089972bd 100644
--- a/pkg/models/allocation.go
+++ b/pkg/models/allocation.go
@@ -115,4 +115,5 @@ type ComputeAllocationMembership struct {
StartTime time.Time `json:"start_time" db:"start_time"`
EndTime time.Time `json:"end_time" db:"end_time"`
MembershipStatus AllocationStatus `json:"membership_status" db:"membership_status"` // ACTIVE, INACTIVE, etc.
+ Role string `json:"role" db:"role"` // PI, CO_PI, ALLOCATION_MANAGER, MEMBER
}
diff --git a/pkg/posix/username_test.go b/pkg/posix/username_test.go
index 57b4f28f4..95cb6b8f2 100644
--- a/pkg/posix/username_test.go
+++ b/pkg/posix/username_test.go
@@ -62,8 +62,8 @@ func TestBuildBase(t *testing.T) {
},
{
name: "prefix swap",
- first: "Alice", last: "Smith", prefix: "nexus",
- wantBase: "nexus-asmith", wantTrunc: false,
+ first: "Alice", last: "Smith", prefix: "alt",
+ wantBase: "alt-asmith", wantTrunc: false,
},
{
name: "truncation at 32-char limit",
@@ -149,8 +149,8 @@ func TestPrefix(t *testing.T) {
if got := Prefix(); got != "custos" {
t.Errorf("default = %q, want %q", got, "custos")
}
- t.Setenv("POSIX_USERNAME_PREFIX", "nexus")
- if got := Prefix(); got != "nexus" {
- t.Errorf("override = %q, want %q", got, "nexus")
+ t.Setenv("POSIX_USERNAME_PREFIX", "alt")
+ if got := Prefix(); got != "alt" {
+ t.Errorf("override = %q, want %q", got, "alt")
}
}
diff --git a/pkg/service/compute_allocation.go b/pkg/service/compute_allocation.go
index dbc817ea4..424d1d2f0 100644
--- a/pkg/service/compute_allocation.go
+++ b/pkg/service/compute_allocation.go
@@ -22,10 +22,21 @@ import (
"database/sql"
"fmt"
+ "github.com/apache/airavata-custos/internal/store"
"github.com/apache/airavata-custos/pkg/events"
"github.com/apache/airavata-custos/pkg/models"
)
+// ListComputeAllocations returns a paginated, filterable slice of compute
+// allocations plus a total count.
+func (s *Service) ListComputeAllocations(ctx context.Context, f store.AllocationListFilter) ([]models.ComputeAllocation, int, error) {
+ rows, total, err := s.allocs.List(ctx, f)
+ if err != nil {
+ return nil, 0, fmt.Errorf("list compute allocations: %w", err)
+ }
+ return rows, total, nil
+}
+
// CreateComputeAllocation persists a new compute allocation. The referenced
// project and compute cluster must already exist. If alloc.ID is empty a new
// UUID is generated; if Status is empty it defaults to ACTIVE.
diff --git a/pkg/service/compute_allocation_change_request.go b/pkg/service/compute_allocation_change_request.go
index 06bda3024..5f9c4a05e 100644
--- a/pkg/service/compute_allocation_change_request.go
+++ b/pkg/service/compute_allocation_change_request.go
@@ -22,9 +22,20 @@ import (
"database/sql"
"fmt"
+ "github.com/apache/airavata-custos/internal/store"
"github.com/apache/airavata-custos/pkg/models"
)
+// ListChangeRequests returns change requests filtered by the supplied
+// criteria. Used by the portal's admin change-request queue.
+func (s *Service) ListChangeRequests(ctx context.Context, f store.ChangeRequestListFilter) ([]models.ComputeAllocationChangeRequest, error) {
+ rows, err := s.changeRequests.List(ctx, f)
+ if err != nil {
+ return nil, fmt.Errorf("list change requests: %w", err)
+ }
+ return rows, nil
+}
+
// CreateComputeAllocationChangeRequest records a new change request against a
// compute allocation. The referenced allocation must exist and a requester
// must be supplied. ChangeStatus defaults to "PENDING" and Timestamp to the
diff --git a/pkg/service/compute_allocation_membership.go b/pkg/service/compute_allocation_membership.go
index cbf60cc5a..25cdb64c4 100644
--- a/pkg/service/compute_allocation_membership.go
+++ b/pkg/service/compute_allocation_membership.go
@@ -22,6 +22,7 @@ import (
"database/sql"
"fmt"
+ "github.com/apache/airavata-custos/internal/store"
"github.com/apache/airavata-custos/pkg/events"
"github.com/apache/airavata-custos/pkg/models"
)
@@ -57,6 +58,17 @@ func (s *Service) CreateComputeAllocationMembership(ctx context.Context, m *mode
} else if existing != nil {
return nil, fmt.Errorf("%w: user %q already has a membership on allocation %q", ErrAlreadyExists, m.UserID, m.ComputeAllocationID)
}
+ if m.Role == "PI" {
+ if rows, err := s.memberships.FindByAllocation(ctx, m.ComputeAllocationID); err != nil {
+ return nil, fmt.Errorf("check PI uniqueness: %w", err)
+ } else {
+ for _, x := range rows {
+ if x.Role == "PI" {
+ return nil, fmt.Errorf("%w: allocation %q already has a PI (%q)", ErrAlreadyExists, m.ComputeAllocationID, x.UserID)
+ }
+ }
+ }
+ }
if m.ID == "" {
m.ID = newID()
@@ -88,19 +100,34 @@ func (s *Service) GetComputeAllocationMembership(ctx context.Context, id string)
return m, nil
}
-// ListMembersForAllocation returns every membership recorded against the
-// given allocation, ordered by start_time ascending.
-func (s *Service) ListMembersForAllocation(ctx context.Context, allocationID string) ([]models.ComputeAllocationMembership, error) {
+// ListMembersForAllocation returns memberships for an allocation joined with
+// users so each row carries display_name and email. Display fields live on
+// store.MembershipWithUser, not on the core entity.
+func (s *Service) ListMembersForAllocation(ctx context.Context, allocationID string) ([]store.MembershipWithUser, error) {
if allocationID == "" {
return nil, fmt.Errorf("%w: compute_allocation_id is required", ErrInvalidInput)
}
- rows, err := s.memberships.FindByAllocation(ctx, allocationID)
+ rows, err := s.memberships.FindByAllocationWithUser(ctx, allocationID)
if err != nil {
return nil, fmt.Errorf("list members for allocation: %w", err)
}
return rows, nil
}
+// ListMembersForProject derives project members from allocation memberships:
+// one row per distinct user with a membership on any of the project's
+// allocations. The project's PI is always asserted with role=PI.
+func (s *Service) ListMembersForProject(ctx context.Context, projectID string) ([]store.MembershipWithUser, error) {
+ if projectID == "" {
+ return nil, fmt.Errorf("%w: project_id is required", ErrInvalidInput)
+ }
+ rows, err := s.memberships.FindByProjectWithUser(ctx, projectID)
+ if err != nil {
+ return nil, fmt.Errorf("list members for project: %w", err)
+ }
+ return rows, nil
+}
+
// ListAllocationsForUser returns every membership held by the given user,
// ordered by start_time ascending.
func (s *Service) ListAllocationsForUser(ctx context.Context, userID string) ([]models.ComputeAllocationMembership, error) {
diff --git a/pkg/service/interface.go b/pkg/service/interface.go
index d76736a06..75518ba6e 100644
--- a/pkg/service/interface.go
+++ b/pkg/service/interface.go
@@ -23,6 +23,7 @@ import (
"context"
"time"
+ "github.com/apache/airavata-custos/internal/store"
"github.com/apache/airavata-custos/pkg/models"
)
@@ -177,7 +178,8 @@ type ComputeAllocationChangeRequestEventService interface {
type ComputeAllocationMembershipService interface {
CreateComputeAllocationMembership(ctx context.Context, m *models.ComputeAllocationMembership) (*models.ComputeAllocationMembership, error)
GetComputeAllocationMembership(ctx context.Context, id string) (*models.ComputeAllocationMembership, error)
- ListMembersForAllocation(ctx context.Context, allocationID string) ([]models.ComputeAllocationMembership, error)
+ ListMembersForAllocation(ctx context.Context, allocationID string) ([]store.MembershipWithUser, error)
+ ListMembersForProject(ctx context.Context, projectID string) ([]store.MembershipWithUser, error)
ListAllocationsForUser(ctx context.Context, userID string) ([]models.ComputeAllocationMembership, error)
UpdateComputeAllocationMembership(ctx context.Context, m *models.ComputeAllocationMembership) (*models.ComputeAllocationMembership, error)
UpdateMembershipStatus(ctx context.Context, id string, status models.AllocationStatus) (*models.ComputeAllocationMembership, error)
diff --git a/pkg/service/mock.go b/pkg/service/mock.go
index 99b2c7dc4..3539694af 100644
--- a/pkg/service/mock.go
+++ b/pkg/service/mock.go
@@ -5,6 +5,7 @@ package service
import (
"context"
+ "github.com/apache/airavata-custos/internal/store"
"github.com/apache/airavata-custos/pkg/models"
"sync"
"time"
@@ -296,9 +297,12 @@ var _ CoreService = &CoreServiceMock{}
// ListEventsForChangeRequestFunc: func(ctx context.Context, changeRequestID string) ([]models.ComputeAllocationChangeRequestEvent, error) {
// panic("mock out the ListEventsForChangeRequest method")
// },
-// ListMembersForAllocationFunc: func(ctx context.Context, allocationID string) ([]models.ComputeAllocationMembership, error) {
+// ListMembersForAllocationFunc: func(ctx context.Context, allocationID string) ([]store.MembershipWithUser, error) {
// panic("mock out the ListMembersForAllocation method")
// },
+// ListMembersForProjectFunc: func(ctx context.Context, projectID string) ([]store.MembershipWithUser, error) {
+// panic("mock out the ListMembersForProject method")
+// },
// ListOverridesForMembershipFunc: func(ctx context.Context, membershipID string) ([]models.ComputeAllocationMembershipResourceOverride, error) {
// panic("mock out the ListOverridesForMembership method")
// },
@@ -694,7 +698,10 @@ type CoreServiceMock struct {
ListEventsForChangeRequestFunc func(ctx context.Context, changeRequestID string) ([]models.ComputeAllocationChangeRequestEvent, error)
// ListMembersForAllocationFunc mocks the ListMembersForAllocation method.
- ListMembersForAllocationFunc func(ctx context.Context, allocationID string) ([]models.ComputeAllocationMembership, error)
+ ListMembersForAllocationFunc func(ctx context.Context, allocationID string) ([]store.MembershipWithUser, error)
+
+ // ListMembersForProjectFunc mocks the ListMembersForProject method.
+ ListMembersForProjectFunc func(ctx context.Context, projectID string) ([]store.MembershipWithUser, error)
// ListOverridesForMembershipFunc mocks the ListOverridesForMembership method.
ListOverridesForMembershipFunc func(ctx context.Context, membershipID string) ([]models.ComputeAllocationMembershipResourceOverride, error)
@@ -1508,6 +1515,13 @@ type CoreServiceMock struct {
// AllocationID is the allocationID argument value.
AllocationID string
}
+ // ListMembersForProject holds details about calls to the ListMembersForProject method.
+ ListMembersForProject []struct {
+ // Ctx is the ctx argument value.
+ Ctx context.Context
+ // ProjectID is the projectID argument value.
+ ProjectID string
+ }
// ListOverridesForMembership holds details about calls to the ListOverridesForMembership method.
ListOverridesForMembership []struct {
// Ctx is the ctx argument value.
@@ -1891,6 +1905,7 @@ type CoreServiceMock struct {
lockListDiffsForAllocation sync.RWMutex
lockListEventsForChangeRequest sync.RWMutex
lockListMembersForAllocation sync.RWMutex
+ lockListMembersForProject sync.RWMutex
lockListOverridesForMembership sync.RWMutex
lockListOverridesForResource sync.RWMutex
lockListPrivilegeHolders sync.RWMutex
@@ -5339,7 +5354,7 @@ func (mock *CoreServiceMock) ListEventsForChangeRequestCalls() []struct {
}
// ListMembersForAllocation calls ListMembersForAllocationFunc.
-func (mock *CoreServiceMock) ListMembersForAllocation(ctx context.Context, allocationID string) ([]models.ComputeAllocationMembership, error) {
+func (mock *CoreServiceMock) ListMembersForAllocation(ctx context.Context, allocationID string) ([]store.MembershipWithUser, error) {
if mock.ListMembersForAllocationFunc == nil {
panic("CoreServiceMock.ListMembersForAllocationFunc: method is nil but CoreService.ListMembersForAllocation was just called")
}
@@ -5374,6 +5389,42 @@ func (mock *CoreServiceMock) ListMembersForAllocationCalls() []struct {
return calls
}
+// ListMembersForProject calls ListMembersForProjectFunc.
+func (mock *CoreServiceMock) ListMembersForProject(ctx context.Context, projectID string) ([]store.MembershipWithUser, error) {
+ if mock.ListMembersForProjectFunc == nil {
+ panic("CoreServiceMock.ListMembersForProjectFunc: method is nil but CoreService.ListMembersForProject was just called")
+ }
+ callInfo := struct {
+ Ctx context.Context
+ ProjectID string
+ }{
+ Ctx: ctx,
+ ProjectID: projectID,
+ }
+ mock.lockListMembersForProject.Lock()
+ mock.calls.ListMembersForProject = append(mock.calls.ListMembersForProject, callInfo)
+ mock.lockListMembersForProject.Unlock()
+ return mock.ListMembersForProjectFunc(ctx, projectID)
+}
+
+// ListMembersForProjectCalls gets all the calls that were made to ListMembersForProject.
+// Check the length with:
+//
+// len(mockedCoreService.ListMembersForProjectCalls())
+func (mock *CoreServiceMock) ListMembersForProjectCalls() []struct {
+ Ctx context.Context
+ ProjectID string
+} {
+ var calls []struct {
+ Ctx context.Context
+ ProjectID string
+ }
+ mock.lockListMembersForProject.RLock()
+ calls = mock.calls.ListMembersForProject
+ mock.lockListMembersForProject.RUnlock()
+ return calls
+}
+
// ListOverridesForMembership calls ListOverridesForMembershipFunc.
func (mock *CoreServiceMock) ListOverridesForMembership(ctx context.Context, membershipID string) ([]models.ComputeAllocationMembershipResourceOverride, error) {
if mock.ListOverridesForMembershipFunc == nil {
diff --git a/pkg/service/project.go b/pkg/service/project.go
index 53d57617f..3a54d1c15 100644
--- a/pkg/service/project.go
+++ b/pkg/service/project.go
@@ -22,6 +22,7 @@ import (
"database/sql"
"fmt"
+ "github.com/apache/airavata-custos/internal/store"
"github.com/apache/airavata-custos/pkg/events"
"github.com/apache/airavata-custos/pkg/models"
)
@@ -106,6 +107,39 @@ func (s *Service) ListProjectsByPI(ctx context.Context, piUserID string) ([]mode
return projects, nil
}
+// ListProjects returns a paginated, filterable slice of projects plus a total
+// count.
+func (s *Service) ListProjects(ctx context.Context, f store.ProjectListFilter) ([]models.Project, int, error) {
+ rows, total, err := s.projs.List(ctx, f)
+ if err != nil {
+ return nil, 0, fmt.Errorf("list projects: %w", err)
+ }
+ return rows, total, nil
+}
+
+// GetProjectWithPI returns the project joined with its PI's display fields,
+// so handlers don't fan a separate GetUser per row.
+func (s *Service) GetProjectWithPI(ctx context.Context, id string) (*store.ProjectWithPI, error) {
+ p, err := s.projs.FindByIDWithPI(ctx, id)
+ if err != nil {
+ return nil, fmt.Errorf("get project: %w", err)
+ }
+ if p == nil {
+ return nil, ErrNotFound
+ }
+ return p, nil
+}
+
+// ListProjectsWithPI is ListProjects with the PI user joined in a single
+// query.
+func (s *Service) ListProjectsWithPI(ctx context.Context, f store.ProjectListFilter) ([]store.ProjectWithPI, int, error) {
+ rows, total, err := s.projs.ListWithPI(ctx, f)
+ if err != nil {
+ return nil, 0, fmt.Errorf("list projects: %w", err)
+ }
+ return rows, total, nil
+}
+
// UpdateProject persists changes to an existing project. Fields left
// blank/zero on the supplied record fall back to the stored value.
func (s *Service) UpdateProject(ctx context.Context, project *models.Project) error {