event

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2023 License: Apache-2.0 Imports: 16 Imported by: 12

Documentation

Overview

Package event provides primitives to work with CNE specification: https://github.com/redhat-cne/spec.

Index

Constants

View Source
const (
	// TextPlain ...
	TextPlain = "text/plain"
	// TextJSON ...
	TextJSON = "text/json"
	// ApplicationJSON ...
	ApplicationJSON = "application/json"
)

Variables

This section is empty.

Functions

func ReadDataJSON

func ReadDataJSON(out *Data, reader io.Reader) error

ReadDataJSON ...

func ReadJSON

func ReadJSON(out *Event, reader io.Reader) error

ReadJSON ...

func StringOfApplicationJSON

func StringOfApplicationJSON() *string

StringOfApplicationJSON returns a string pointer to "application/json"

func StringOfTextPlain

func StringOfTextPlain() *string

StringOfTextPlain returns a string pointer to "text/plain"

func WriteDataJSON

func WriteDataJSON(in *Data, writer io.Writer) error

WriteDataJSON writes the in data in the provided writer. Note: this function assumes the input event is valid.

func WriteJSON

func WriteJSON(in *Event, writer io.Writer) error

WriteJSON writes the in event in the provided writer. Note: this function assumes the input event is valid.

Types

type Data

type Data struct {
	Version string      `json:"version" example:"v1"`
	Values  []DataValue `json:"values"`
}

Data ... cloud native events data Data Json payload is as follows,

{
	"version": "v1.0",
	"values": [{
		"resource": "/sync/sync-status/sync-state",
		"dataType": "notification",
		"valueType": "enumeration",
		"value": "ACQUIRING-SYNC"
		}, {
		"resource": "/sync/sync-status/sync-state",
		"dataType": "metric",
		"valueType": "decimal64.3",
		"value": 100.3
		}, {
		"resource": "/redfish/v1/Systems",
		"dataType": "notification",
		"valueType": "redfish-event",
		"value": {
		    "@odata.context": "/redfish/v1/$metadata#Event.Event",
		    "@odata.type": "#Event.v1_3_0.Event",
		    "Context": "any string is valid",
		    "Events": [{"EventId": "2162", "MemberId": "615703", "MessageId": "TMP0100"}],
		    "Id": "5e004f5a-e3d1-11eb-ae9c-3448edf18a38",
		    "Name": "Event Array"
		}
	}]
}

func (*Data) AppendValues

func (d *Data) AppendValues(v DataValue)

AppendValues ...

func (*Data) GetValues

func (d *Data) GetValues() []DataValue

GetValues ...

func (*Data) GetVersion

func (d *Data) GetVersion() string

GetVersion ...

func (Data) MarshalJSON

func (d Data) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom json marshal method used when this type is marshaled using json.Marshal.

func (*Data) SetValues

func (d *Data) SetValues(v []DataValue)

SetValues ...

func (*Data) SetVersion

func (d *Data) SetVersion(s string) error

SetVersion ...

func (*Data) UnmarshalJSON

func (d *Data) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json unmarshal method used when this type is unmarshaled using json.Unmarshal.

type DataType

type DataType string

DataType ...

const (
	// NOTIFICATION ...
	NOTIFICATION DataType = "notification"
	// METRIC ...
	METRIC DataType = "metric"
)

type DataValue

type DataValue struct {
	Resource  string      `json:"resource" example:"/cluster/node/clock"`
	DataType  DataType    `json:"dataType" example:"metric"`
	ValueType ValueType   `json:"valueType" example:"decimal64.3"`
	Value     interface{} `json:"value" example:"100.3"`
}

DataValue ... DataValue Json payload is as follows,

{
	"resource": "/cluster/node/ptp",
	"dataType": "notification",
	"valueType": "enumeration",
	"value": "ACQUIRING-SYNC"
}

func (*DataValue) GetResource

func (v *DataValue) GetResource() string

GetResource ...

func (*DataValue) SetResource

func (v *DataValue) SetResource(r string) error

SetResource ...

type Event

type Event struct {
	// ID of the event; must be non-empty and unique within the scope of the producer.
	// +required
	ID string `json:"id" example:"789be75d-7ac3-472e-bbbc-6d62878aad4a"`
	// Type - The type of the occurrence which has happened.
	// +required
	Type string `json:"type" example:"event.sync.sync-status.synchronization-state-change"`
	// Source - The source of the occurrence which has happened.
	// +required
	Source string `json:"source" example:"/cluster/node/example.com/ptp/clock_realtime"`
	// DataContentType - the Data content type
	// +required
	DataContentType *string `json:"dataContentType" example:"application/json"`
	// Time - A Timestamp when the event happened.
	// +required
	Time *types.Timestamp `json:"time" example:"2021-02-05T17:31:00Z"`
	// DataSchema - A link to the schema that the `Data` attribute adheres to.
	// +optional
	DataSchema *types.URI `json:"dataSchema,omitempty"`
	// +required
	Data *Data `json:"data" `
}

Event represents the canonical representation of a Cloud Native Event. Event Json payload is as follows,

{
	"id": "5ce55d17-9234-4fee-a589-d0f10cb32b8e",
	"type": "event.sync.sync-status.synchronization-state-change",
	"source": "/cluster/node/example.com/ptp/clock_realtime",
	"time": "2021-02-05T17:31:00Z",
	"data": {
		"version": "v1.0",
		"values": [{
			"resource": "/sync/sync-status/sync-state",
			"dataType": "notification",
			"valueType": "enumeration",
			"value": "ACQUIRING-SYNC"
			}, {
			"resource": "/sync/sync-status/sync-state",
			"dataType": "metric",
			"valueType": "decimal64.3",
			"value": 100.3
			}]
		}
}

Event request model

func (Event) Clone

func (e Event) Clone() Event

Clone clones data

func (*Event) GetCloudNativeEvents

func (e *Event) GetCloudNativeEvents(ce *cloudevent.Event) (err error)

GetCloudNativeEvents get event data from cloud events object if its valid else return error

func (*Event) GetData

func (e *Event) GetData() *Data

GetData ...

func (*Event) GetDataContentType

func (e *Event) GetDataContentType() string

GetDataContentType implements Reader.DataContentType

func (*Event) GetDataSchema

func (e *Event) GetDataSchema() string

GetDataSchema implements Reader.DataSchema

func (*Event) GetDataValue

func (e *Event) GetDataValue() (data []DataValue, err error)

GetDataValue encodes the given payload

func (*Event) GetID

func (e *Event) GetID() string

GetID implements Reader.ID

func (*Event) GetSource added in v0.2.0

func (e *Event) GetSource() string

GetSource implements Reader.Source

func (*Event) GetTime

func (e *Event) GetTime() time.Time

GetTime implements Reader.Time

func (*Event) GetType

func (e *Event) GetType() string

GetType implements Reader.Type

func (Event) JSONString added in v0.2.0

func (e Event) JSONString() string

JSONString returns a pretty-printed representation of the Event.

func (Event) MarshalJSON

func (e Event) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom json marshal method used when this type is marshaled using json.Marshal.

func (*Event) NewCloudEvent

func (e *Event) NewCloudEvent(ps *pubsub.PubSub) (*cloudevent.Event, error)

NewCloudEvent create new cloud event from cloud native events and pubsub

func (*Event) SetData

func (e *Event) SetData(data Data)

SetData ...

func (*Event) SetDataContentType

func (e *Event) SetDataContentType(ct string)

SetDataContentType implements Writer.SetDataContentType

func (*Event) SetDataSchema

func (e *Event) SetDataSchema(s string) error

SetDataSchema implements Writer.SetDataSchema

func (*Event) SetDataValue

func (e *Event) SetDataValue(dataType DataType, obj interface{}) (err error)

SetDataValue encodes the given payload

func (*Event) SetID

func (e *Event) SetID(id string)

SetID implements Writer.SetID

func (*Event) SetSource added in v0.2.0

func (e *Event) SetSource(s string)

SetSource implements Writer.SetSource

func (*Event) SetTime

func (e *Event) SetTime(t time.Time)

SetTime implements Writer.SetTime

func (*Event) SetType

func (e *Event) SetType(t string)

SetType implements Writer.SetType

func (Event) String

func (e Event) String() string

String returns a pretty-printed representation of the Event.

func (*Event) UnmarshalJSON

func (e *Event) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json unmarshal method used when this type is unmarshaled using json.Unmarshal.

type Reader

type Reader interface {
	// GetType returns event.GetType().
	GetType() string
	// GetTime returns event.GetTime().
	GetTime() time.Time
	// GetID returns event.GetID().
	GetID() string
	// GetDataSchema returns event.GetDataSchema().
	GetDataSchema() string
	// GetDataContentType returns event.GetDataContentType().
	GetDataContentType() string
	// GetData returns event.GetData()
	GetData() *Data
	// Clone clones the event .
	Clone() Event
	// String returns a pretty-printed representation of the EventContext.
	String() string
}

Reader is the interface for reading through an event from attributes.

type ValueType

type ValueType string

ValueType ...

const (
	// ENUMERATION ...
	ENUMERATION ValueType = "enumeration"
	// DECIMAL ...
	DECIMAL ValueType = "decimal64.3"
	// REDFISH_EVENT ...
	REDFISH_EVENT ValueType = "redfish-event" //nolint:all
)

type Writer

type Writer interface {
	// SetType performs event.SetType.
	SetType(string)
	// SetID performs event.SetID.
	SetID(string)
	// SetTime performs event.SetTime.
	SetTime(time.Time)
	// SetDataSchema performs event.SetDataSchema.
	SetDataSchema(string) error
	// SetDataContentType performs event.SetDataContentType.
	SetDataContentType(string)
	// SetData
	SetData(Data)
}

Writer is the interface for writing through an event onto attributes. If an error is thrown by a sub-component, Writer caches the error internally and exposes errors with a call to event.Validate().

Directories

Path Synopsis
Package ptp provides specifications for PTP extensions
Package ptp provides specifications for PTP extensions
Package redfish provides specifications for Redfish extensions
Package redfish provides specifications for Redfish extensions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL