Skip to content

Commit

Permalink
feat: support oem method to obtain composition status on all resource…
Browse files Browse the repository at this point in the history
… blocks in one request
  • Loading branch information
HJ-Fan committed Sep 9, 2024
1 parent 643f744 commit def5324
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 8 deletions.
1 change: 1 addition & 0 deletions pkg/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type BackendOperations interface {
CreateSession(context.Context, *ConfigurationSettings, *CreateSessionRequest) (*CreateSessionResponse, error)
DeleteSession(context.Context, *ConfigurationSettings, *DeleteSessionRequest) (*DeleteSessionResponse, error)
GetMemoryResourceBlocks(context.Context, *ConfigurationSettings, *MemoryResourceBlocksRequest) (*MemoryResourceBlocksResponse, error)
GetMemoryResourceBlocksCompositionStatus(context.Context, *ConfigurationSettings, *MemoryResourceBlocksCompositionRequest) (*MemoryResourceBlocksCompositionResponse, error)
GetMemoryResourceBlockById(context.Context, *ConfigurationSettings, *MemoryResourceBlockByIdRequest) (*MemoryResourceBlockByIdResponse, error)
GetPorts(context.Context, *ConfigurationSettings, *GetPortsRequest) (*GetPortsResponse, error)
GetHostPortPcieDevices(ctx context.Context, settings *ConfigurationSettings, req *GetPortsRequest) (*GetPortsResponse, error)
Expand Down
68 changes: 68 additions & 0 deletions pkg/backend/httpfish.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,74 @@ func (service *httpfishService) GetMemoryResourceBlocks(ctx context.Context, set
return &MemoryResourceBlocksResponse{MemoryResources: memoryResources, Status: "Success", ServiceError: nil}, nil
}

// GetMemoryResourceBlocks: Request Memory Resource Block information from the backends
func (service *httpfishService) GetMemoryResourceBlocksCompositionStatus(ctx context.Context, settings *ConfigurationSettings, req *MemoryResourceBlocksCompositionRequest) (*MemoryResourceBlocksCompositionResponse, error) {
logger := klog.FromContext(ctx)
logger.V(4).Info("====== GetMemoryResourceBlocksCompositionStatus ======")
logger.V(4).Info("memory resource blocks", "request", req)

memoryResourcesStatus := make([]MemoryResourceBlock, 0)

session := service.service.session.(*Session)

response := session.query(HTTPOperation.GET, session.redfishPaths[ResourceBlocksKey])

if response.err != nil {
return &MemoryResourceBlocksCompositionResponse{Status: "Failure", ServiceError: response.err}, response.err
}

oemField, err := response.valueFromJSON("Oem")

if err == nil {
compositionStatus := oemField.(map[string]interface{})["Seagate"].(map[string]interface{})["CompositionStatus"].([]map[string]interface{})
for _, resourceBlock := range compositionStatus {
// Update CompositionState using the Reserved and CompositionState values from Redfish

compositionState := resourceBlock["CompositionState"].(string)
reserved := resourceBlock["Reserved"].(bool)

resourceState := findResourceState(&compositionState, reserved)

blockInfo := MemoryResourceBlock{
Id: getIdFromOdataId(resourceBlock["@odata.id"].(string)),
CompositionStatus: MemoryResourceBlockCompositionStatus{
CompositionState: *resourceState,
},
}
memoryResourcesStatus = append(memoryResourcesStatus, blockInfo)
}

} else {

resourceBlocks, _ := response.arrayFromJSON("Members")
for _, resourceBlock := range resourceBlocks {
blockDetails := session.query(HTTPOperation.GET, resourceBlock.(map[string]interface{})["@odata.id"].(string))

if !(blockDetails.err == nil && blockDetails.isMemoryResourceBlock()) {
continue
}

uri, _ := blockDetails.stringFromJSON("@odata.id")

compositionStatus, _ := blockDetails.valueFromJSON("CompositionStatus")
reserved := compositionStatus.(map[string]interface{})["Reserved"].(bool)
compositionState := compositionStatus.(map[string]interface{})["CompositionState"].(string)

resourceState := findResourceState(&compositionState, reserved)

blockInfo := MemoryResourceBlock{
Id: getIdFromOdataId(uri),
CompositionStatus: MemoryResourceBlockCompositionStatus{
CompositionState: *resourceState,
},
}
memoryResourcesStatus = append(memoryResourcesStatus, blockInfo)
}
}

return &MemoryResourceBlocksCompositionResponse{MemoryResourcesStatus: memoryResourcesStatus, Status: "Success", ServiceError: nil}, nil
}

// GetMemoryResourceBlockById: Request a particular Memory Resource Block information by ID from the backends
func (service *httpfishService) GetMemoryResourceBlockById(ctx context.Context, settings *ConfigurationSettings, req *MemoryResourceBlockByIdRequest) (*MemoryResourceBlockByIdResponse, error) {
logger := klog.FromContext(ctx)
Expand Down
9 changes: 9 additions & 0 deletions pkg/backend/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ type MemoryResourceBlocksResponse struct {
ServiceError error // Any error returned by the service
}

type MemoryResourceBlocksCompositionRequest struct {
}

type MemoryResourceBlocksCompositionResponse struct {
MemoryResourcesStatus []MemoryResourceBlock // Array to hold detail of memory resources
Status string // The status of the request
ServiceError error // Any error returned by the service
}

type GetPortsRequest struct {
}

Expand Down
32 changes: 25 additions & 7 deletions pkg/manager/blade.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,26 @@ type RequestComposeMemory struct {
Qos openapi.Qos
}

// updateAllResourceStatus: Update the composition status on all resource blocks
func (b *Blade) updateAllResourceStatus(ctx context.Context) error {
logger := klog.FromContext(ctx)
logger.V(3).Info(">>>>>> updateAllResourceStatus: ")

request := backend.MemoryResourceBlocksCompositionRequest{}
settings := backend.ConfigurationSettings{}
compositionResponse, err := b.backendOps.GetMemoryResourceBlocksCompositionStatus(ctx, &settings, &request)

if err != nil {
return fmt.Errorf("unable to udpate resource block composition status")
}

for _, blockInfo := range compositionResponse.MemoryResourcesStatus {
block, _ := b.GetResourceById(ctx, blockInfo.Id)
block.details.CompositionStatus.CompositionState = blockInfo.CompositionStatus.CompositionState.String()
}
return nil
}

// ComposeMemory: Create a new memory region of the requested size and, if a port is requested, assign it to a port.
// In ComposeMemory, there are two steps in backend, one is AllocateMemory and the other one is AssignMemory
// AllocateMemory creates memory region (memorychunk), AssignMemory connects the memory region to an port
Expand All @@ -168,14 +188,12 @@ func (b *Blade) ComposeMemory(ctx context.Context, r *RequestComposeMemory) (*op
logger.V(4).Info(">>>>>> ComposeMemory: ", "portId", r.PortId, "SizeMiB", r.SizeMib, "Qos", r.Qos, "bladeId", b.Id, "applianceId", b.ApplianceId)

// Update all resource details
for _, resource := range b.Resources {
_, err := resource.GetDetails(ctx)
if err != nil {
newErr := fmt.Errorf("get details failure on blade [%s] resource [%s]: %w", b.Id, resource.Id, err)
logger.Error(newErr, "failure: compose memory")
return nil, &common.RequestError{StatusCode: err.(*common.RequestError).StatusCode, Err: newErr}
}
err := b.updateAllResourceStatus(ctx)
if err != nil {
logger.Error(err, "failure: compose memory")
return nil, &common.RequestError{StatusCode: common.StatusBladeGetMemoryResourceBlocksFailure, Err: err}
}

resourceIds := b.findResourcesByQoS(r.SizeMib, r.Qos)
if resourceIds == nil {
newErr := fmt.Errorf("unable to find resources by qos during compose: appliance [%s] blade [%s] request [%v]", b.ApplianceId, b.Id, r)
Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type CxlBladePort struct {
backendOps backend.BackendOperations
}

func NewCxlBladePortById(ctx context.Context, applianceId, bladeId, portId string, ops backend.BackendOperations) (*CxlBladePort) {
func NewCxlBladePortById(ctx context.Context, applianceId, bladeId, portId string, ops backend.BackendOperations) *CxlBladePort {
logger := klog.FromContext(ctx)
logger.V(4).Info(">>>>>> NewCxlBladePortById: ", "portId", portId, "bladeId", bladeId, "applianceId", applianceId, "backend", ops.GetBackendInfo(ctx).BackendName)

Expand Down

0 comments on commit def5324

Please sign in to comment.