Skip to content

Commit

Permalink
fix: [cxl-host] Collection return empty list instead of null when the…
Browse files Browse the repository at this point in the history
…re is zero member
  • Loading branch information
HJ-Fan committed Sep 19, 2024
1 parent 9215d1c commit 34991f4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions cmd/cxl-host/service/cxl_host_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (s *CxlHostApiService) RedfishV1AccountServiceAccountsGet(ctx context.Conte
Description: "Accounts Collection",
Name: "Accounts Collection",
Oem: nil,
Members: []redfishapi.OdataV4IdRef{},
}

// Iterate over all account usernames adding each to the collection
Expand Down Expand Up @@ -187,6 +188,7 @@ func (s *CxlHostApiService) RedfishV1AccountServiceRolesGet(ctx context.Context)
Description: "Roles Collection",
Name: "Roles Collection",
Oem: nil,
Members: []redfishapi.OdataV4IdRef{},
}

// Iterate over all roles adding each to the collection
Expand Down Expand Up @@ -484,6 +486,7 @@ func (s *CxlHostApiService) RedfishV1FabricsFabricIdSwitchesSwitchIdPortsGet(ctx
Description: fabricId + " " + switchId + " Ports",
Name: fabricId + " " + switchId + " Ports",
Oem: nil,
Members: []redfishapi.OdataV4IdRef{},
}

// Iterate over all possible Fabrics adding each to the collection
Expand Down Expand Up @@ -546,6 +549,7 @@ func (s *CxlHostApiService) RedfishV1FabricsGet(ctx context.Context) (redfishapi
Description: "Fabrics Collection",
Name: "Fabrics Collection",
Oem: nil,
Members: []redfishapi.OdataV4IdRef{},
}

// Iterate over all possible Fabrics adding each to the collection
Expand Down Expand Up @@ -640,17 +644,14 @@ func (s *CxlHostApiService) RedfishV1SessionServiceSessionsGet(ctx context.Conte
Description: "Sessions",
Name: "Sessions",
Oem: nil,
Members: []redfishapi.OdataV4IdRef{},
}

// Iterate over all possible sessions adding each to the collection
sessions := accounts.GetSessions()
collection.MembersodataCount = int64(len(sessions))
if collection.MembersodataCount > 0 {
for id := range sessions {
collection.Members = append(collection.Members, redfishapi.OdataV4IdRef{OdataId: fmt.Sprintf("/redfish/v1/SessionService/Sessions/%s", id)})
}
} else {
collection.Members = []redfishapi.OdataV4IdRef{}
for id := range sessions {
collection.Members = append(collection.Members, redfishapi.OdataV4IdRef{OdataId: fmt.Sprintf("/redfish/v1/SessionService/Sessions/%s", id)})
}

return redfishapi.Response(http.StatusOK, collection), nil
Expand Down Expand Up @@ -748,6 +749,7 @@ func (s *CxlHostApiService) RedfishV1ChassisChassisIdMemoryDomainsGet(ctx contex
OdataId: "/redfish/v1/Chassis/" + chassisId + "/MemoryDomains",
OdataType: "#MemoryDomainCollection.MemoryDomainCollection",
Name: "MemoryDomain Collection",
Members: []redfishapi.OdataV4IdRef{},
}
collection.Members = append(collection.Members, redfishapi.OdataV4IdRef{OdataId: fmt.Sprintf("/redfish/v1/Chassis/%s/MemoryDomains/DIMMs", chassisId)})
if CheckMemoryDomainName("CXL") {
Expand Down Expand Up @@ -806,6 +808,7 @@ func (s *CxlHostApiService) RedfishV1ChassisChassisIdMemoryDomainsMemoryDomainId
OdataId: "/redfish/v1/Chassis/" + chassisId + "/MemoryDomains/" + memoryDomainId + "/MemoryChunks",
OdataType: "#MemoryChunksCollection.MemoryChunksCollection",
Name: "Memory Chunks Collection",
Members: []redfishapi.OdataV4IdRef{},
}

if memoryDomainId == "DIMMs" { // each numa node with dimm attached ( numa node with CPU ) is mapped to a memory chunk
Expand Down Expand Up @@ -972,6 +975,7 @@ func (s *CxlHostApiService) RedfishV1ChassisChassisIdPCIeDevicesPCIeDeviceIdCXLL
Description: "CXL Logical Device Collection",
MembersodataNextLink: "",
Name: "CXL Logical Device Collection",
Members: []redfishapi.OdataV4IdRef{},
}
for _, id := range GetCXLLogicalDeviceIds(pCIeDeviceId) {
collection.Members = append(collection.Members, redfishapi.OdataV4IdRef{
Expand Down Expand Up @@ -1053,6 +1057,7 @@ func (s *CxlHostApiService) RedfishV1ChassisChassisIdPCIeDevicesPCIeDeviceIdPCIe
Description: "PCIeFunction Collection",
Name: "PCIe Function Collection",
Oem: nil,
Members: []redfishapi.OdataV4IdRef{},
}

for _, id := range GetPCIeFunctionIds(pCIeDeviceId) {
Expand Down Expand Up @@ -1298,6 +1303,7 @@ func (s *CxlHostApiService) RedfishV1SystemsComputerSystemIdMemoryDomainsGet(ctx
OdataId: "/redfish/v1/Systems/" + computerSystemId + "/MemoryDomains",
OdataType: "#MemoryDomainCollection.MemoryDomainCollection",
Name: "MemoryDomain Collection",
Members: []redfishapi.OdataV4IdRef{},
}
collection.Members = append(collection.Members, redfishapi.OdataV4IdRef{OdataId: fmt.Sprintf("/redfish/v1/Systems/%s/MemoryDomains/DIMMs", computerSystemId)})
if CheckMemoryDomainName("CXL") {
Expand Down Expand Up @@ -1342,6 +1348,7 @@ func (s *CxlHostApiService) RedfishV1SystemsComputerSystemIdMemoryDomainsMemoryD
OdataId: "/redfish/v1/Systems/" + computerSystemId + "/MemoryDomains/" + memoryDomainId + "/MemoryChunks",
OdataType: "#MemoryChunksCollection.MemoryChunksCollection",
Name: "Memory Chunks Collection",
Members: []redfishapi.OdataV4IdRef{},
}

if memoryDomainId == "DIMMs" { // each numa node with dimm attached ( numa node with CPU ) is mapped to a memory chunk
Expand Down Expand Up @@ -1421,6 +1428,7 @@ func (s *CxlHostApiService) RedfishV1SystemsComputerSystemIdMemoryGet(ctx contex
Description: "Memory Collection",
MembersodataNextLink: "",
Name: "Memory Collection",
Members: []redfishapi.OdataV4IdRef{},
}
for i := 1; i <= GetCXLDevCnt(); i++ {
collection.Members = append(collection.Members,
Expand Down

0 comments on commit 34991f4

Please sign in to comment.