Skip to content

Commit

Permalink
Merge pull request #1076 from chauberahul1993/ODIM-6787
Browse files Browse the repository at this point in the history
Load event subscription table data into cache memory
  • Loading branch information
amar-shalgar authored Jan 20, 2023
2 parents 328e8e7 + b65b6a6 commit 3693ded
Show file tree
Hide file tree
Showing 28 changed files with 1,272 additions and 454 deletions.
2 changes: 1 addition & 1 deletion build/Redis/createschema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Set "User:admin" '{"UserName":"admin","Password":"O01bKrP7Tzs7YoO3YvQt4pRa2J_R6
Set "role:Administrator" '{"@odata.type":"","RoleId":"Administrator","Name":"","Description":"","IsPredefined":true,"AssignedPrivileges":["ConfigureSelf","Login","ConfigureUsers","ConfigureComponents","ConfigureManager"],"OemPrivileges":null,"@odata.context":"","@odata.id":""}'
Set "role:Operator" '{"@odata.type":"","RoleId":"Operator","Name":"","Description":"","IsPredefined":true,"AssignedPrivileges":["ConfigureSelf","Login","ConfigureComponents"],"OemPrivileges":null,"@odata.context":"","@odata.id":""}'
Set "role:ReadOnly" '{"@odata.type":"","RoleId":"ReadOnly","Name":"","Description":"","IsPredefined":true,"AssignedPrivileges":["ConfigureSelf","Login"],"OemPrivileges":null,"@odata.context":"","@odata.id":""}'
ZAdd "Subscription" 0 '{"UserName":"","SubscriptionID":"0","Destination":"","Name":"default","Context":"","EventTypes":["Alert"],"MessageIds":null,"Protocol":"Redfish","SubscriptionType":"RedfishEvent","EventFormatType":"","SubordinateResources":true,"ResourceTypes":null,"OriginResources":[],"Hosts":[],"DeliveryRetryPolicy":"RetryForever"}'
ZAdd "Subscription" 0 '{"UserName":"","SubscriptionID":"0","Hosts":[],"EventDestination":{"DeliveryRetryPolicy":"RetryForever","Destination":"","Name":"default","Context":"","EventTypes":["Alert"],"MessageIds":[],"Protocol":"Redfish","SubscriptionType":"RedfishEvent","EventFormatType":"","SubordinateResources":true,"ResourceTypes":[],"OriginResources":[]}}'
keys *
SAVE
HERE
Expand Down
5 changes: 3 additions & 2 deletions install/Docker/dockerfiles/scripts/add-hosts/add-hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ package main
import (
"flag"
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/sirupsen/logrus"
"io/ioutil"
"os"
"strings"
"time"

"github.com/fsnotify/fsnotify"
"github.com/sirupsen/logrus"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion install/Docker/dockerfiles/scripts/redis-createschema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Set "User:admin" '{"UserName":"admin","Password":"O01bKrP7Tzs7YoO3YvQt4pRa2J_R6
Set "role:Administrator" '{"@odata.type":"","RoleId":"Administrator","Name":"","Description":"","IsPredefined":true,"AssignedPrivileges":["ConfigureSelf","Login","ConfigureUsers","ConfigureComponents","ConfigureManager"],"OemPrivileges":null,"@odata.context":"","@odata.id":""}'
Set "role:Operator" '{"@odata.type":"","RoleId":"Operator","Name":"","Description":"","IsPredefined":true,"AssignedPrivileges":["ConfigureSelf","Login","ConfigureComponents"],"OemPrivileges":null,"@odata.context":"","@odata.id":""}'
Set "role:ReadOnly" '{"@odata.type":"","RoleId":"ReadOnly","Name":"","Description":"","IsPredefined":true,"AssignedPrivileges":["ConfigureSelf","Login"],"OemPrivileges":null,"@odata.context":"","@odata.id":""}'
ZAdd "Subscription" 0 '{"UserName":"","SubscriptionID":"0","Destination":"","Name":"default","Context":"","EventTypes":["Alert"],"MessageIds":null,"Protocol":"Redfish","SubscriptionType":"RedfishEvent","EventFormatType":"","SubordinateResources":true,"ResourceTypes":null,"OriginResources":[],"Hosts":[],"DeliveryRetryPolicy":"RetryForever"}'
ZAdd "Subscription" 0 '{"UserName":"","SubscriptionID":"0","Hosts":[],"EventDestination":{"DeliveryRetryPolicy":"RetryForever","Destination":"","Name":"default","Context":"","EventTypes":["Alert"],"MessageIds":[],"Protocol":"Redfish","SubscriptionType":"RedfishEvent","EventFormatType":"","SubordinateResources":true,"ResourceTypes":[],"OriginResources":[]}}'
keys *
SAVE
HERE
Expand Down
168 changes: 130 additions & 38 deletions lib-dmtf/model/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ type SyslogFacility string
// that will be forwarded. The service shall forward all messages
// equal to or greater than the value in this property. The value
// `All` shall indicate all severities.

//DeliveryRetryPolicy - The subscription delivery retry policy for events,
// where the subscription type is RedfishEvent.
type DeliveryRetryPolicy string

type SyslogSeverity string

// This property shall contain the authentication method for the SMTP server.
Expand Down Expand Up @@ -246,6 +251,26 @@ const (
// A Warning.
SyslogSeverityWarning SyslogSeverity = "Warning"

// DeliveryRetryPolicy for events. Currently ODIM only support subscriptions
// of type RetryForever.
// DeliveryRetryForever - The subscription is not suspended or terminated,
// and attempts at delivery of future events shall continue regardless of
// the number of retries.
DeliveryRetryForever DeliveryRetryPolicy = "RetryForever"

// DeliveryRetryForeverWithBackoff - The subscription is not suspended or
// terminated, and attempts at delivery of future events shall continue
// regardless of the number of retries, but issued over time according to
// a service-defined backoff algorithm
DeliveryRetryForeverWithBackoff DeliveryRetryPolicy = "RetryForeverWithBackoff"

// DeliverySuspendRetries - The subscription is suspended after the maximum
// number of retries is reached
DeliverySuspendRetries DeliveryRetryPolicy = "SuspendRetries"

// DeliveryTerminateAfterRetries : The subscription is terminated after the
// maximum number of retries is reached.
DeliveryTerminateAfterRetries DeliveryRetryPolicy = "TerminateAfterRetries"
//SMTP Authentcation method Auto-detect
SMTPAuthenticationAutoDetect SMTPAuthentication = "AutoDetect"

Expand Down Expand Up @@ -317,44 +342,111 @@ type EventRecord struct {
// in the Event payload.
// Reference : EventDestination.v1_12_0.json
type EventDestination struct {
ODataContext string `json:"@odata.context,omitempty"`
ODataEtag string `json:"@odata.etag,omitempty"`
ODataId string `json:"@odata.id"`
ODataType string `json:"@odata.type"`
Actions *Actions `json:"Actions,omitempty"`
Certificates *Link `json:"Certificates,omitempty"`
ClientCertificates *Link `json:"ClientCertificates,omitempty"`
Context string `json:"Context"`
DeliveryRetryPolicy string `json:"DeliveryRetryPolicy,omitempty"`
Description string `json:"Description,omitempty"`
Destination string `json:"Destination"`
EventFormatType string `json:"EventFormatType,omitempty"`
EventTypes []string `json:"EventTypes,omitempty"`
ExcludeMessageIds []string `json:"ExcludeMessageIds,omitempty"`
ExcludeRegistryPrefixes []string `json:"ExcludeRegistryPrefixes,omitempty"`
HeartbeatIntervalMins int `json:"HeartbeatIntervalMinutes,omitempty"`
HttpHeaders []string `json:"HttpHeaders,omitempty"`
ID string `json:"Id"`
IncludeOriginOfCondition bool `json:"IncludeOriginOfCondition,omitempty"`
MessageIds []string `json:"MessageIds,omitempty"`
MetricReportDefinitions *Link `json:"MetricReportDefinitions,omitempty"`
MetricReportDefinitionsCount int `json:[email protected],omitempty`
Name string `json:"Name"`
OEMProtocol string `json:"OEMProtocol,omitempty"`
OEMSubscriptionType string `json:"OEMSubscriptionType"`
Oem interface{} `json:"Oem,omitempty"`
OriginResources []string `json:"OriginResources,omitempty"`
OriginResourcesCount int `json:[email protected],omitempty`
Protocol string `json:"Protocol"`
RegistryPrefixes []string `json:"RegistryPrefixes,omitempty"`
ResourceTypes []string `json:"ResourceTypes,omitempty"`
SNMP SNMPSettings `json:"SNMP,omitempty"`
SendHeartbeat bool `json:"SendHeartbeat,omitempty"`
Status Status `json:"Status,omitempty"`
SubordinateResources bool `json:"SubordinateResources,omitempty"`
SubscriptionType SubscriptionType `json:"SubscriptionType,omitempty"`
SyslogFilters SyslogFilter `json:"SyslogFilters,omitempty"`
VerifyCertificate bool `json:"VerifyCertificate,omitempty"`
ODataContext string `json:"@odata.context,omitempty"`
ODataEtag string `json:"@odata.etag,omitempty"`
ODataId string `json:"@odata.id"`
ODataType string `json:"@odata.type"`
Actions *Actions `json:"Actions,omitempty"`
Certificates *Link `json:"Certificates,omitempty"`
ClientCertificates *Link `json:"ClientCertificates,omitempty"`
Context string `json:"Context"`
DeliveryRetryPolicy DeliveryRetryPolicy `json:"DeliveryRetryPolicy,omitempty"`
Description string `json:"Description,omitempty"`
Destination string `json:"Destination"`
EventFormatType string `json:"EventFormatType,omitempty"`
EventTypes []string `json:"EventTypes,omitempty"`
ExcludeMessageIds []string `json:"ExcludeMessageIds,omitempty"`
ExcludeRegistryPrefixes []string `json:"ExcludeRegistryPrefixes,omitempty"`
HeartbeatIntervalMins int `json:"HeartbeatIntervalMinutes,omitempty"`
HttpHeaders []string `json:"HttpHeaders,omitempty"`
ID string `json:"Id"`
IncludeOriginOfCondition bool `json:"IncludeOriginOfCondition,omitempty"`
MessageIds []string `json:"MessageIds,omitempty"`
MetricReportDefinitions *Link `json:"MetricReportDefinitions,omitempty"`
MetricReportDefinitionsCount int `json:[email protected],omitempty`
Name string `json:"Name"`
OEMProtocol string `json:"OEMProtocol,omitempty"`
OEMSubscriptionType string `json:"OEMSubscriptionType"`
Oem interface{} `json:"Oem,omitempty"`
OriginResources []string `json:"OriginResources,omitempty"`
OriginResourcesCount int `json:[email protected],omitempty`
Protocol string `json:"Protocol"`
RegistryPrefixes []string `json:"RegistryPrefixes,omitempty"`
ResourceTypes []string `json:"ResourceTypes,omitempty"`
SNMP SNMPSettings `json:"SNMP,omitempty"`
SendHeartbeat bool `json:"SendHeartbeat,omitempty"`
Status Status `json:"Status,omitempty"`
SubordinateResources bool `json:"SubordinateResources,omitempty"`
SubscriptionType SubscriptionType `json:"SubscriptionType,omitempty"`
SyslogFilters SyslogFilter `json:"SyslogFilters,omitempty"`
VerifyCertificate bool `json:"VerifyCertificate,omitempty"`
}

//IsValidSubscriptionType validate subscription type is valid,
func (subscriptionType SubscriptionType) IsValidSubscriptionType() bool {
switch subscriptionType {
case SubscriptionTypeRedFishEvent, SubscriptionTypeOEM,
SubscriptionTypeSNMPInform, SubscriptionTypeSNMPTrap,
SubscriptionTypeSyslog, SubscriptionTySubscriptionTypeSSE:
return true
default:
return false
}
}

// IsSubscriptionTypeSupported method return true if subscription type is RedfishEvent
func (subscriptionType SubscriptionType) IsSubscriptionTypeSupported() bool {
switch subscriptionType {
case SubscriptionTypeRedFishEvent:
return true
default:
return false
}
}
func (subscriptionType SubscriptionType) ToString() string {
return string(subscriptionType)
}

func (deliveryRetryPolicy DeliveryRetryPolicy) ToString() string {
return string(deliveryRetryPolicy)
}

func (eventType EventType) ToString() string {
return string(eventType)
}

//IsValidEventType return true if event type is valid
func (eventType EventType) IsValidEventType() bool {
switch eventType {
case EventTypeAlert, EventTypeMetricReport, EventTypeOther,
EventTypeResourceRemoved, EventTypeResourceAdded,
EventTypeResourceUpdated, EventTypeStatusChange:
return true
default:
return false
}
}

// IsValidDeliveryRetryPolicyType is validate DeliveryRetryPolicy value valid or not
func (deliveryRetryPolicy DeliveryRetryPolicy) IsValidDeliveryRetryPolicyType() bool {
switch deliveryRetryPolicy {
case DeliveryRetryForever, DeliverySuspendRetries,
DeliveryTerminateAfterRetries, DeliveryRetryForeverWithBackoff:
return true
default:
return false
}
}

// IsDeliveryRetryPolicyTypeSupported is return true if DeliveryRetryPolicy
// is RetryForever. Currently ODIM support RetryForever value
func (deliveryRetryPolicy DeliveryRetryPolicy) IsDeliveryRetryPolicyTypeSupported() bool {
switch deliveryRetryPolicy {
case DeliveryRetryForever:
return true
default:
return false
}
}

// EventDestinationAction contain the available
Expand Down
57 changes: 57 additions & 0 deletions lib-persistence-manager/persistencemgr/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -1722,3 +1722,60 @@ func (p *ConnPool) DeleteAggregateHosts(index, aggregateID string) error {
}
return nil
}

// This function retrieves all data for a given index from sorted sets
// This maybe used to get all event/device subscriptions and aggregate hosts
func (p *ConnPool) GetAllDataByIndex(index string) ([]string, error) {
dList, ferror := p.getAllDataFromSortedList(index)
if ferror != nil {
return []string{}, ferror
}
EvtSubscriptions, extracterr := getDataAsStringList(dList)
if extracterr != nil {
return []string{}, ferror
}

return EvtSubscriptions, nil
}

//getAllDataFromSortedList function read all member from index
func (p *ConnPool) getAllDataFromSortedList(index string) (data interface{}, err error) {
readConn := p.ReadPool.Get()
defer readConn.Close()
const cursor float64 = 0

d, getErr := readConn.Do("ZCOUNT", index, 0, 0)
if getErr != nil {
return nil, fmt.Errorf("Unable to fetch count of data for index : " +
index + " : " +
getErr.Error())
}
countData := d.(int64)

data, getErr = readConn.Do("ZSCAN", index, cursor, "MATCH",
"*", "COUNT", countData)
if getErr != nil {
return []string{},
fmt.Errorf("Error while fetching data for " + index + " : " + getErr.Error())
}
return data, nil
}

// getDataAsStringList function convert list of interface into string
// filter priority value from list
func getDataAsStringList(d interface{}) ([]string, error) {
var dataList []string
var err error
if len(d.([]interface{})) > 1 {
data, err := redis.Strings(d.([]interface{})[1], err)
if err != nil {
return []string{}, fmt.Errorf("error while marshaling data : " + err.Error())
}
for i := 0; i < len(data); i++ {
if data[i] != "0" {
dataList = append(dataList, data[i])
}
}
}
return dataList, nil
}
1 change: 1 addition & 0 deletions lib-utilities/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ type DeviceSubscription struct {
EventHostIP string `json:"EventHostIP,omitempty"`
OriginResources []string `json:"OriginResources"`
Location string `json:"location,omitempty"`
OriginResource string `json:"OriginResource"`
}

// URIWithNoAuth contains the list of URI's which does not require authentication
Expand Down
Loading

0 comments on commit 3693ded

Please sign in to comment.