Skip to content

Commit

Permalink
Added new function for getsource details
Browse files Browse the repository at this point in the history
  • Loading branch information
sriteja-sabbineni committed May 26, 2023
1 parent dc21c8c commit 14c1ba5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 19 deletions.
20 changes: 20 additions & 0 deletions svc-aggregation/agcommon/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ var SupportedConnectionMethodTypes = map[string]bool{
var (
//GetResourceDetailsFunc function pointer for the agmodel.GetResourceDetails
GetResourceDetailsFunc = agmodel.GetResourceDetails
//GetResourceDetailsBytableNameFunc function pointer for the agmodel.GetResourceDetailsBytableName
GetResourceDetailsBytableNameFunc = agmodel.GetResourceDetailsBytableName
// GetAllKeysFromTableFunc function pointer for the agmodel.GetAllKeysFromTable
GetAllKeysFromTableFunc = agmodel.GetAllKeysFromTable
//GetAllSystemsFunc function pointer for the agmodel.GetAllSystems
Expand Down Expand Up @@ -126,6 +128,24 @@ func GetStorageResources(ctx context.Context, oid string) map[string]interface{}
return resourceData
}

// GetStorageResourcesBytableName will get the resource details from the database for the given odata id and table name
func GetStorageResourcesBytableName(ctx context.Context, table, oid string) map[string]interface{} {
resourceData := make(map[string]interface{})
data, dbErr := GetResourceDetailsBytableNameFunc(ctx, table, oid)
if dbErr != nil {
l.LogWithFields(ctx).Error("Unable to get system data : " + dbErr.Error())
return resourceData
}
// unmarshall the resourceData
err := JSONUnMarshalFunc([]byte(data), &resourceData)
if err != nil {
l.LogWithFields(ctx).Error("Unable to unmarshall the data: " + err.Error())
return resourceData
}

return resourceData
}

// AddConnectionMethods will add the connection method type and variant into DB
func (e *DBInterface) AddConnectionMethods(connectionMethodConf []config.ConnectionMethodConf) error {
aggTransactionID := uuid.New()
Expand Down
19 changes: 19 additions & 0 deletions svc-aggregation/agmodel/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,25 @@ func GetResourceDetails(ctx context.Context, key string) (string, *errors.Error)
return resource, nil
}

// GetResourceDetailsBytableName fetches a resource from database using key and table name

func GetResourceDetailsBytableName(ctx context.Context, table, key string) (string, *errors.Error) {
conn, err := common.GetDBConnection(common.InMemory)
if err != nil {
return "", errors.PackError(err.ErrNo(), err)
}
resourceData, err := conn.Read(table, key)
if err != nil {
return "", errors.PackError(err.ErrNo(), "error while trying to get resource details: ", err.Error())
}
var resource string
if errs := json.Unmarshal([]byte(resourceData), &resource); errs != nil {
return "", errors.PackError(errors.UndefinedErrorType, errs)
}
l.LogWithFields(ctx).Debugf("resource details: %s", resource)
return resource, nil
}

// GetString is used to retrive index values of type string
/* Inputs:
1. index is the index name to search with
Expand Down
2 changes: 0 additions & 2 deletions svc-aggregation/rpc/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,13 @@ func (a *Aggregator) AddAggregationSource(ctx context.Context, req *aggregatorpr
generateResponse(authResp, resp)
return resp, nil
}
fmt.Println("AddAggregationSource********")
sessionUserName, err := a.connector.GetSessionUserName(ctx, req.SessionToken)
if err != nil {
errMsg := "Unable to get session username: " + err.Error()
generateResponse(common.GeneralError(http.StatusUnauthorized, response.NoValidSession, errMsg, nil, nil), resp)
l.LogWithFields(ctx).Error(errMsg)
return resp, nil
}
fmt.Println("session AddAggregationSource********", sessionUserName)
// parsing the AggregationSourceRequest
var addRequest system.AggregationSource
err = json.Unmarshal(req.RequestBody, &addRequest)
Expand Down
20 changes: 12 additions & 8 deletions svc-aggregation/system/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,19 +646,21 @@ func (h *respHolder) getSystemInfo(ctx context.Context, taskID string, progress

var computeSystem map[string]interface{}
err = json.Unmarshal(body, &computeSystem)

if err != nil {
h.lock.Lock()
h.ErrorMessage = "error while trying unmarshal response body: " + err.Error()
h.StatusMessage = response.InternalError
h.StatusCode = http.StatusInternalServerError
h.lock.Unlock()
return computeSystemID, oidKey, progress, err
}

}
oid := computeSystem["@odata.id"].(string)
computeSystemID = computeSystem["Id"].(string)
computeSystemUUID := computeSystem["UUID"].(string)
oidKey = keyFormation(oid, computeSystemID, req.DeviceUUID)

if !req.UpdateFlag {
indexList, err := agmodel.GetString("UUID", computeSystemUUID)
if err != nil {
Expand Down Expand Up @@ -686,11 +688,12 @@ func (h *respHolder) getSystemInfo(ctx context.Context, taskID string, progress
h.TraversedLinks[req.OID] = true
h.SystemURL = append(h.SystemURL, oidKey)
var retrievalLinks = make(map[string]bool)

getLinks(computeSystem, retrievalLinks, false)
removeRetrievalLinks(retrievalLinks, oid, config.Data.AddComputeSkipResources.SkipResourceListUnderSystem, h.TraversedLinks)

req.SystemID = computeSystemID
req.ParentOID = oid

for resourceOID, oemFlag := range retrievalLinks {
estimatedWork := alottedWork / int32(len(retrievalLinks))
resourceOID = strings.TrimSuffix(resourceOID, "/")
Expand All @@ -700,6 +703,7 @@ func (h *respHolder) getSystemInfo(ctx context.Context, taskID string, progress
}
json.Unmarshal([]byte(updatedResourceData), &computeSystem)
err = agmodel.SaveBMCInventory(h.InventoryData)

if err != nil {
h.lock.Lock()
h.ErrorMessage = "error while trying to save data: " + err.Error()
Expand All @@ -708,14 +712,16 @@ func (h *respHolder) getSystemInfo(ctx context.Context, taskID string, progress
h.lock.Unlock()
return computeSystemID, oidKey, progress, err
}

searchForm := createServerSearchIndex(ctx, computeSystem, oidKey, req.DeviceUUID)

//save the search form here

if req.UpdateFlag {
err = agmodel.UpdateIndex(searchForm, oidKey, computeSystemUUID, req.BMCAddress)
} else {
err = agmodel.SaveIndex(searchForm, oidKey, computeSystemUUID, req.BMCAddress)
}

if err != nil {
h.ErrorMessage = "error while trying save index values: " + err.Error()
h.StatusMessage = response.InternalError
Expand Down Expand Up @@ -816,7 +822,6 @@ func (h *respHolder) getStorageInfo(ctx context.Context, progress int32, alotted

func createServerSearchIndex(ctx context.Context, computeSystem map[string]interface{}, oidKey, deviceUUID string) map[string]interface{} {
var searchForm = make(map[string]interface{})

if val, ok := computeSystem["MemorySummary"]; ok {
memSum := val.(map[string]interface{})
searchForm["MemorySummary/TotalSystemMemoryGiB"] = memSum["TotalSystemMemoryGiB"].(float64)
Expand All @@ -836,7 +841,6 @@ func createServerSearchIndex(ctx context.Context, computeSystem map[string]inter
if _, ok := computeSystem["PowerState"]; ok {
searchForm["PowerState"] = computeSystem["PowerState"].(string)
}

// saving the firmware version
if !strings.Contains(oidKey, "/Storage") {
firmwareVersion, _ := getFirmwareVersion(ctx, oidKey, deviceUUID)
Expand All @@ -852,7 +856,7 @@ func createServerSearchIndex(ctx context.Context, computeSystem map[string]inter
storage := val.(map[string]interface{})
storageCollectionOdataID = storage["@odata.id"].(string)
}
storageCollection := agcommon.GetStorageResources(ctx, strings.TrimSuffix(storageCollectionOdataID, "/"))
storageCollection := agcommon.GetStorageResourcesBytableName(ctx, "StorageCollection", strings.TrimSuffix(storageCollectionOdataID, "/"))
storageMembers := storageCollection["Members"]
if storageMembers != nil {
var capacity []float64
Expand All @@ -861,13 +865,13 @@ func createServerSearchIndex(ctx context.Context, computeSystem map[string]inter
// Loop through all the storage members collection and discover all of them
for _, object := range storageMembers.([]interface{}) {
storageODataID := object.(map[string]interface{})["@odata.id"].(string)
storageRes := agcommon.GetStorageResources(ctx, strings.TrimSuffix(storageODataID, "/"))
storageRes := agcommon.GetStorageResourcesBytableName(ctx, "Storage", strings.TrimSuffix(storageODataID, "/"))
drives := storageRes["Drives"]
if drives != nil {
quantity += len(drives.([]interface{}))
for _, drive := range drives.([]interface{}) {
driveODataID := drive.(map[string]interface{})["@odata.id"].(string)
driveRes := agcommon.GetStorageResources(ctx, strings.TrimSuffix(driveODataID, "/"))
driveRes := agcommon.GetStorageResourcesBytableName(ctx, "Drives", strings.TrimSuffix(driveODataID, "/"))
capInBytes := driveRes["CapacityBytes"]
// convert bytes to gb in decimal format
if capInBytes != nil {
Expand Down
11 changes: 2 additions & 9 deletions svc-aggregation/system/rediscoverinventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"net/http"
"strconv"
"strings"
"sync"

"github.com/ODIM-Project/ODIM/lib-utilities/common"
"github.com/ODIM-Project/ODIM/lib-utilities/config"
Expand All @@ -41,13 +40,10 @@ const (
RediscoverResourcesActionName = "RediscoverResources"
)

var mutex sync.Mutex

// RediscoverSystemInventory is the handler for redicovering system whenever the restrat event detected in event service
// It deletes old data and Discovers Computersystem & Chassis and its top level odata.ID links and store them in inmemory db.
func (e *ExternalInterface) RediscoverSystemInventory(ctx context.Context, deviceUUID, systemURL string, updateFlag bool) {
l.LogWithFields(ctx).Info("Rediscovery of the BMC with ID " + deviceUUID + " is started.")

var resp response.RPC
systemURL = strings.TrimSuffix(systemURL, "/")
data := strings.Split(systemURL, "/")
Expand Down Expand Up @@ -163,6 +159,7 @@ func (e *ExternalInterface) RediscoverSystemInventory(ctx context.Context, devic
if strings.Contains(systemURL, "/Storage") {
l.LogWithFields(ctx).Debugf("get storage info request data for %s: %s", req.OID, string(req.Data))
_, progress, _ = h.getStorageInfo(ctx, progress, systemsEstimatedWork, req)

} else {
l.LogWithFields(ctx).Debugf("get system info request data for %s: %s", req.OID, string(req.Data))
_, _, progress, _ = h.getSystemInfo(ctx, "", progress, systemsEstimatedWork, req)
Expand All @@ -171,12 +168,12 @@ func (e *ExternalInterface) RediscoverSystemInventory(ctx context.Context, devic
req.OID = "/redfish/v1/Chassis"
chassisEstimatedWork := int32(15)
progress = h.getAllRootInfo(ctx, "", progress, chassisEstimatedWork, req, config.Data.AddComputeSkipResources.SkipResourceListUnderChassis)

//rediscovering the Manager Information
req.OID = "/redfish/v1/Managers"
managerEstimatedWork := int32(15)
progress = h.getAllRootInfo(ctx, "", progress, managerEstimatedWork, req, config.Data.AddComputeSkipResources.SkipResourceListUnderManager)
agmodel.SaveBMCInventory(h.InventoryData)

}

var responseBody = map[string]string{
Expand All @@ -185,7 +182,6 @@ func (e *ExternalInterface) RediscoverSystemInventory(ctx context.Context, devic

resp.StatusCode = http.StatusCreated
resp.Body = responseBody

l.LogWithFields(ctx).Info("Rediscovery of the BMC with ID " + deviceUUID + " is now complete.")
}

Expand Down Expand Up @@ -323,7 +319,6 @@ func (e *ExternalInterface) isServerRediscoveryRequired(ctx context.Context, dev
return true

}

key = strings.Replace(systemKey, "Systems", "Chassis", -1)
keys, err := agmodel.GetAllMatchingDetails("Chassis", key, common.InMemory)
if err != nil || len(keys) == 0 {
Expand Down Expand Up @@ -381,8 +376,6 @@ func deleteSubordinateResource(ctx context.Context, deviceUUID string) {
var deleteKeys []string
l.LogWithFields(ctx).Info("Initiated removal of subordinate resource for the BMC with ID " +
deviceUUID + " from the in-memory DB")
mutex.Lock()
defer mutex.Unlock()
keys, err := agmodel.GetAllMatchingDetails("*", deviceUUID, common.InMemory)
if err != nil {
l.LogWithFields(ctx).Error("Unable to fetch all matching keys from system reset table: " + err.Error())
Expand Down

0 comments on commit 14c1ba5

Please sign in to comment.