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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions rest-api/api/internal/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ import (

"github.com/NVIDIA/infra-controller-rest/db/pkg/db/paginator"

echo "github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
temporalClient "go.temporal.io/sdk/client"
tmocks "go.temporal.io/sdk/mocks"

"github.com/NVIDIA/infra-controller-rest/api/internal/config"
"github.com/NVIDIA/infra-controller-rest/api/pkg/api/handler/util/common"
_ "github.com/NVIDIA/infra-controller-rest/api/pkg/api/model"
sc "github.com/NVIDIA/infra-controller-rest/api/pkg/client/site"
cconfig "github.com/NVIDIA/infra-controller-rest/common/pkg/config"
cutil "github.com/NVIDIA/infra-controller-rest/common/pkg/util"
cdb "github.com/NVIDIA/infra-controller-rest/db/pkg/db"
cdbm "github.com/NVIDIA/infra-controller-rest/db/pkg/db/model"
cdbu "github.com/NVIDIA/infra-controller-rest/db/pkg/util"
echo "github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
temporalClient "go.temporal.io/sdk/client"
tmocks "go.temporal.io/sdk/mocks"
)

func Test_InitAPIServer(t *testing.T) {
Expand Down Expand Up @@ -165,7 +167,7 @@ func Test_Audit(t *testing.T) {
assert.Equal(t, http.StatusUnauthorized, rec.Code)
// check if the audit log entry was created
aeDAO := cdbm.NewAuditEntryDAO(dbSession)
entries, count, err := aeDAO.GetAll(context.Background(), nil, cdbm.AuditEntryFilterInput{OrgName: cdb.GetStrPtr("wdksahew1rqv")}, paginator.PageInput{})
entries, count, err := aeDAO.GetAll(context.Background(), nil, cdbm.AuditEntryFilterInput{OrgName: cutil.GetPtr("wdksahew1rqv")}, paginator.PageInput{})
assert.NoError(t, err)
assert.Len(t, entries, 1)
assert.Equal(t, count, 1)
Expand Down
30 changes: 15 additions & 15 deletions rest-api/api/pkg/api/handler/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ func (cah CreateAllocationHandler) Handle(c echo.Context) error {
}

// Create a status detail record for the child IPBlock
_, serr = sdDAO.CreateFromParams(ctx, tx, childIPBlock.ID.String(), *cdb.GetStrPtr(cdbm.IPBlockStatusReady),
cdb.GetStrPtr("Child IP Block is ready for use"))
_, serr = sdDAO.CreateFromParams(ctx, tx, childIPBlock.ID.String(), *cutil.GetPtr(cdbm.IPBlockStatusReady),
cutil.GetPtr("Child IP Block is ready for use"))
if serr != nil {
logger.Error().Err(serr).Msg("error creating Status Detail DB entry for IP Block in Allocation Constraint")
return cutil.NewAPIError(http.StatusInternalServerError, "Failed to create Status Detail ipblock entry for Allocation Constraint", nil)
Expand Down Expand Up @@ -343,8 +343,8 @@ func (cah CreateAllocationHandler) Handle(c echo.Context) error {
a = newA

// Create a status detail record for the Allocation
newSsd, serr := sdDAO.CreateFromParams(ctx, tx, a.ID.String(), *cdb.GetStrPtr(cdbm.AllocationStatusRegistered),
cdb.GetStrPtr("received allocation creation request, registered"))
newSsd, serr := sdDAO.CreateFromParams(ctx, tx, a.ID.String(), *cutil.GetPtr(cdbm.AllocationStatusRegistered),
cutil.GetPtr("received allocation creation request, registered"))
if serr != nil {
logger.Error().Err(serr).Msg("error creating Status Detail DB entry")
return cutil.NewAPIError(http.StatusInternalServerError, "Failed to create Status Detail for Allocation", nil)
Expand Down Expand Up @@ -690,7 +690,7 @@ func (gaah GetAllAllocationHandler) Handle(c echo.Context) error {
providerFilter := sharedFilter
providerFilter.InfrastructureProviderID = &provider.ID
providerFilter.TenantIDs = filterTenantIDs
providerAllocations, _, err := aDAO.GetAll(ctx, nil, providerFilter, cdbp.PageInput{Limit: cdb.GetIntPtr(cdbp.TotalLimit)}, nil)
providerAllocations, _, err := aDAO.GetAll(ctx, nil, providerFilter, cdbp.PageInput{Limit: cutil.GetPtr(cdbp.TotalLimit)}, nil)
if err != nil {
logger.Error().Err(err).Msg("error getting Allocations from Provider perspective")
return cutil.NewAPIErrorResponse(c, http.StatusInternalServerError, "Failed to retrieve Allocations, DB error", nil)
Expand All @@ -703,7 +703,7 @@ func (gaah GetAllAllocationHandler) Handle(c echo.Context) error {
if tenant != nil {
tenantFilter := sharedFilter
tenantFilter.TenantIDs = []uuid.UUID{tenant.ID}
tenantAllocations, _, err := aDAO.GetAll(ctx, nil, tenantFilter, cdbp.PageInput{Limit: cdb.GetIntPtr(cdbp.TotalLimit)}, nil)
tenantAllocations, _, err := aDAO.GetAll(ctx, nil, tenantFilter, cdbp.PageInput{Limit: cutil.GetPtr(cdbp.TotalLimit)}, nil)
if err != nil {
logger.Error().Err(err).Msg("error getting Allocations from Tenant perspective")
return cutil.NewAPIErrorResponse(c, http.StatusInternalServerError, "Failed to retrieve Allocations, DB error", nil)
Expand Down Expand Up @@ -750,7 +750,7 @@ func (gaah GetAllAllocationHandler) Handle(c echo.Context) error {

// Get allocation constraints based on allocation filter by resource type
acDAO := cdbm.NewAllocationConstraintDAO(gaah.dbSession)
alcs, _, err := acDAO.GetAll(ctx, nil, aids, nil, nil, nil, nil, nil, nil, cdb.GetIntPtr(cdbp.TotalLimit), nil)
alcs, _, err := acDAO.GetAll(ctx, nil, aids, nil, nil, nil, nil, nil, nil, cutil.GetPtr(cdbp.TotalLimit), nil)
if err != nil {
logger.Error().Err(err).Msg("error retrieving Allocation Constraints for Allocations from DB")
return cutil.NewAPIErrorResponse(c, http.StatusInternalServerError, "Failed to populate Constraints for Allocations", nil)
Expand Down Expand Up @@ -1059,7 +1059,7 @@ func (uah UpdateAllocationHandler) Handle(c echo.Context) error {
// If this was an IP Block allocation, then update the derived resource name
// Get IP Block Allocation Constraints, if any
acDAO := cdbm.NewAllocationConstraintDAO(uah.dbSession)
ipbAcs, _, derr := acDAO.GetAll(ctx, tx, []uuid.UUID{a.ID}, cdb.GetStrPtr(cdbm.AllocationResourceTypeIPBlock), nil, nil, nil, nil, nil, nil, nil)
ipbAcs, _, derr := acDAO.GetAll(ctx, tx, []uuid.UUID{a.ID}, cutil.GetPtr(cdbm.AllocationResourceTypeIPBlock), nil, nil, nil, nil, nil, nil, nil)
if derr != nil {
logger.Error().Err(derr).Msg("error retrieving Allocation Constraints for Allocation from DB")
return cutil.NewAPIError(http.StatusInternalServerError, "Failed to retrieve Allocation Constraints for Allocation", nil)
Expand Down Expand Up @@ -1089,7 +1089,7 @@ func (uah UpdateAllocationHandler) Handle(c echo.Context) error {
}

sdDAO := cdbm.NewStatusDetailDAO(uah.dbSession)
retSsds, _, derr := sdDAO.GetAllByEntityID(ctx, tx, a.ID.String(), nil, cdb.GetIntPtr(pagination.MaxPageSize), nil)
retSsds, _, derr := sdDAO.GetAllByEntityID(ctx, tx, a.ID.String(), nil, cutil.GetPtr(pagination.MaxPageSize), nil)
if derr != nil {
logger.Error().Err(derr).Msg("error retrieving Status Details for Allocation from DB")
return cutil.NewAPIError(http.StatusInternalServerError, "Failed to retrieve Status Details for Allocation", nil)
Expand Down Expand Up @@ -1233,7 +1233,7 @@ func (dah DeleteAllocationHandler) Handle(c echo.Context) error {

// check dependent objects (instances or subnets for the tenant) in allocation constraints for the allocation
acDAO := cdbm.NewAllocationConstraintDAO(dah.dbSession)
acs, _, derr := acDAO.GetAll(ctx, tx, []uuid.UUID{a.ID}, nil, nil, nil, nil, nil, nil, cdb.GetIntPtr(cdbp.TotalLimit), nil)
acs, _, derr := acDAO.GetAll(ctx, tx, []uuid.UUID{a.ID}, nil, nil, nil, nil, nil, nil, cutil.GetPtr(cdbp.TotalLimit), nil)
if derr != nil && derr != cdb.ErrDoesNotExist {
logger.Error().Err(derr).Msg("error retrieving Allocation Constraints from DB")
return cutil.NewAPIError(http.StatusInternalServerError, "Error getting allocation constraints for allocation", nil)
Expand Down Expand Up @@ -1282,7 +1282,7 @@ func (dah DeleteAllocationHandler) Handle(c echo.Context) error {
SiteIDs: []uuid.UUID{a.SiteID},
InstanceTypeIDs: []uuid.UUID{ac.ResourceTypeID},
},
cdbp.PageInput{Limit: cdb.GetIntPtr(0)},
cdbp.PageInput{Limit: cutil.GetPtr(0)},
nil,
)
if serr != nil {
Expand All @@ -1300,7 +1300,7 @@ func (dah DeleteAllocationHandler) Handle(c echo.Context) error {

// Calculate the tenant/site aggregate capacity for the instance type.
totalConstraintValue, serr := common.GetTotalAllocationConstraintValueForInstanceType(
ctx, tx, dah.dbSession, allocationIDs, &ac.ResourceTypeID, cdb.GetStrPtr(cdbm.AllocationConstraintTypeReserved),
ctx, tx, dah.dbSession, allocationIDs, &ac.ResourceTypeID, cutil.GetPtr(cdbm.AllocationConstraintTypeReserved),
)
if serr != nil {
logger.Error().Err(serr).Msg("error getting total Allocation Constraint value for Instance Type")
Expand All @@ -1309,7 +1309,7 @@ func (dah DeleteAllocationHandler) Handle(c echo.Context) error {

// Calculate how much capacity would be removed by deleting this allocation.
deletedConstraintValue, serr := common.GetTotalAllocationConstraintValueForInstanceType(
ctx, tx, dah.dbSession, []uuid.UUID{a.ID}, &ac.ResourceTypeID, cdb.GetStrPtr(cdbm.AllocationConstraintTypeReserved),
ctx, tx, dah.dbSession, []uuid.UUID{a.ID}, &ac.ResourceTypeID, cutil.GetPtr(cdbm.AllocationConstraintTypeReserved),
)
if serr != nil {
logger.Error().Err(serr).Msg("error getting Allocation Constraint value for Allocation being deleted")
Expand Down Expand Up @@ -1387,7 +1387,7 @@ func (dah DeleteAllocationHandler) Handle(c echo.Context) error {
}

// Get count of subnets for the IP Block
_, sbCount, sserr := sDAO.GetAll(ctx, tx, subnetFilter, cdbp.PageInput{Limit: cdb.GetIntPtr(0)}, []string{})
_, sbCount, sserr := sDAO.GetAll(ctx, tx, subnetFilter, cdbp.PageInput{Limit: cutil.GetPtr(0)}, []string{})
if sserr != nil {
logger.Error().Err(sserr).Str("Constraint ID", ac.DerivedResourceID.String()).Msg("error getting Subnets for Allocation Constraint's IP Block")
return cutil.NewAPIError(http.StatusInternalServerError, "Error retrieving Subnets for Allocation's IP Block'", nil)
Expand All @@ -1398,7 +1398,7 @@ func (dah DeleteAllocationHandler) Handle(c echo.Context) error {
}

// Get count of Vpc Prefixes for the IP Block
_, vpCount, sserr := vpDAO.GetAll(ctx, tx, vpcPrefixFilter, cdbp.PageInput{Limit: cdb.GetIntPtr(0)}, []string{})
_, vpCount, sserr := vpDAO.GetAll(ctx, tx, vpcPrefixFilter, cdbp.PageInput{Limit: cutil.GetPtr(0)}, []string{})
if sserr != nil {
logger.Error().Err(sserr).Str("Constraint ID", ac.DerivedResourceID.String()).Msg("error getting Vpc Prefixes for Allocation Constraint's IP Block")
return cutil.NewAPIError(http.StatusInternalServerError, "Error retrieving Vpc Prefixes for Allocation's IP Block'", nil)
Expand Down
Loading
Loading