mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
Adapt layout of AMQP update to VILLAScontroller protocol, add uptime in IC creation and updates via AMQP; need to check data type of uptime #31
This commit is contained in:
parent
e2bebbc676
commit
d0c6cca76c
5 changed files with 61 additions and 51 deletions
|
@ -129,7 +129,7 @@ type InfrastructureComponent struct {
|
|||
// Type of IC (RTDS, VILLASnode, RTDS, etc.)
|
||||
Type string `json:"type" gorm:"default:''"`
|
||||
// Uptime of the IC
|
||||
Uptime int `json:"uptime" gorm:"default:0"`
|
||||
Uptime float64 `json:"uptime" gorm:"default:0"`
|
||||
// State of the IC
|
||||
State string `json:"state" gorm:"default:''"`
|
||||
// Time of last state update
|
||||
|
|
|
@ -98,7 +98,7 @@ var ICA = database.InfrastructureComponent{
|
|||
Type: "VILLASnode Signal Generator",
|
||||
Category: "Signal Generator",
|
||||
Name: "ACS Demo Signals",
|
||||
Uptime: 0,
|
||||
Uptime: -1.0,
|
||||
State: "idle",
|
||||
Location: "k8s",
|
||||
Description: "A signal generator for testing purposes",
|
||||
|
@ -113,7 +113,7 @@ var ICB = database.InfrastructureComponent{
|
|||
Type: "DPsim",
|
||||
Category: "Simulator",
|
||||
Name: "Test DPsim Simulator",
|
||||
Uptime: 0,
|
||||
Uptime: -1.0,
|
||||
State: "running",
|
||||
Location: "ACS Laboratory",
|
||||
Description: "This is a test description",
|
||||
|
|
|
@ -56,17 +56,18 @@ type Action struct {
|
|||
}
|
||||
|
||||
type ICUpdate struct {
|
||||
State *string `json:"state"`
|
||||
Properties struct {
|
||||
UUID string `json:"uuid"`
|
||||
Name *string `json:"name"`
|
||||
Category *string `json:"category"`
|
||||
Type *string `json:"type"`
|
||||
Location *string `json:"location"`
|
||||
WS_url *string `json:"ws_url"`
|
||||
API_url *string `json:"api_url"`
|
||||
Description *string `json:"description"`
|
||||
} `json:"properties"`
|
||||
Status *struct {
|
||||
UUID string `json:"uuid"`
|
||||
State *string `json:"state"`
|
||||
Name *string `json:"name"`
|
||||
Category *string `json:"category"`
|
||||
Type *string `json:"type"`
|
||||
Location *string `json:"location"`
|
||||
WS_url *string `json:"ws_url"`
|
||||
API_url *string `json:"api_url"`
|
||||
Description *string `json:"description"`
|
||||
Uptime *float64 `json:"uptime"` // TODO check if data type of uptime is float64 or int
|
||||
} `json:"status"`
|
||||
// TODO add JSON start parameter scheme
|
||||
}
|
||||
|
||||
|
@ -261,9 +262,9 @@ func processMessage(message amqp.Delivery) error {
|
|||
return fmt.Errorf("AMQP: Could not unmarshal message to JSON: %v err: %v", string(message.Body), err)
|
||||
}
|
||||
|
||||
if payload.State != nil {
|
||||
if payload.Status != nil {
|
||||
// if a message contains a "state" field, it is an update for an IC
|
||||
ICUUID := payload.Properties.UUID
|
||||
ICUUID := payload.Status.UUID
|
||||
_, err = uuid.Parse(ICUUID)
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -93,20 +93,20 @@ func (s *InfrastructureComponent) getConfigs() ([]database.ComponentConfiguratio
|
|||
func createNewICviaAMQP(payload ICUpdate) error {
|
||||
|
||||
var newICReq AddICRequest
|
||||
newICReq.InfrastructureComponent.UUID = payload.Properties.UUID
|
||||
if payload.Properties.Name == nil ||
|
||||
payload.Properties.Category == nil ||
|
||||
payload.Properties.Type == nil {
|
||||
newICReq.InfrastructureComponent.UUID = payload.Status.UUID
|
||||
if payload.Status.Name == nil ||
|
||||
payload.Status.Category == nil ||
|
||||
payload.Status.Type == nil {
|
||||
// cannot create new IC because required information (name, type, and/or category missing)
|
||||
return fmt.Errorf("AMQP: Cannot create new IC, required field(s) is/are missing: name, type, category")
|
||||
}
|
||||
newICReq.InfrastructureComponent.Name = *payload.Properties.Name
|
||||
newICReq.InfrastructureComponent.Category = *payload.Properties.Category
|
||||
newICReq.InfrastructureComponent.Type = *payload.Properties.Type
|
||||
newICReq.InfrastructureComponent.Name = *payload.Status.Name
|
||||
newICReq.InfrastructureComponent.Category = *payload.Status.Category
|
||||
newICReq.InfrastructureComponent.Type = *payload.Status.Type
|
||||
|
||||
// add optional params
|
||||
if payload.State != nil {
|
||||
newICReq.InfrastructureComponent.State = *payload.State
|
||||
if payload.Status.State != nil {
|
||||
newICReq.InfrastructureComponent.State = *payload.Status.State
|
||||
} else {
|
||||
newICReq.InfrastructureComponent.State = "unknown"
|
||||
}
|
||||
|
@ -116,17 +116,20 @@ func createNewICviaAMQP(payload ICUpdate) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if payload.Properties.WS_url != nil {
|
||||
newICReq.InfrastructureComponent.WebsocketURL = *payload.Properties.WS_url
|
||||
if payload.Status.WS_url != nil {
|
||||
newICReq.InfrastructureComponent.WebsocketURL = *payload.Status.WS_url
|
||||
}
|
||||
if payload.Properties.API_url != nil {
|
||||
newICReq.InfrastructureComponent.APIURL = *payload.Properties.API_url
|
||||
if payload.Status.API_url != nil {
|
||||
newICReq.InfrastructureComponent.APIURL = *payload.Status.API_url
|
||||
}
|
||||
if payload.Properties.Location != nil {
|
||||
newICReq.InfrastructureComponent.Location = *payload.Properties.Location
|
||||
if payload.Status.Location != nil {
|
||||
newICReq.InfrastructureComponent.Location = *payload.Status.Location
|
||||
}
|
||||
if payload.Properties.Description != nil {
|
||||
newICReq.InfrastructureComponent.Description = *payload.Properties.Description
|
||||
if payload.Status.Description != nil {
|
||||
newICReq.InfrastructureComponent.Description = *payload.Status.Description
|
||||
}
|
||||
if payload.Status.Uptime != nil {
|
||||
newICReq.InfrastructureComponent.Uptime = *payload.Status.Uptime
|
||||
}
|
||||
// TODO add JSON start parameter scheme
|
||||
|
||||
|
@ -157,10 +160,10 @@ func createNewICviaAMQP(payload ICUpdate) error {
|
|||
func (s *InfrastructureComponent) updateICviaAMQP(payload ICUpdate) error {
|
||||
|
||||
var updatedICReq UpdateICRequest
|
||||
if payload.State != nil {
|
||||
updatedICReq.InfrastructureComponent.State = *payload.State
|
||||
if payload.Status.State != nil {
|
||||
updatedICReq.InfrastructureComponent.State = *payload.Status.State
|
||||
|
||||
if *payload.State == "gone" {
|
||||
if *payload.Status.State == "gone" {
|
||||
// remove IC from DB
|
||||
log.Println("########## AMQP: Deleting IC with state gone")
|
||||
err := s.delete(true)
|
||||
|
@ -172,27 +175,30 @@ func (s *InfrastructureComponent) updateICviaAMQP(payload ICUpdate) error {
|
|||
|
||||
}
|
||||
}
|
||||
if payload.Properties.Type != nil {
|
||||
updatedICReq.InfrastructureComponent.Type = *payload.Properties.Type
|
||||
if payload.Status.Type != nil {
|
||||
updatedICReq.InfrastructureComponent.Type = *payload.Status.Type
|
||||
}
|
||||
if payload.Properties.Category != nil {
|
||||
updatedICReq.InfrastructureComponent.Category = *payload.Properties.Category
|
||||
if payload.Status.Category != nil {
|
||||
updatedICReq.InfrastructureComponent.Category = *payload.Status.Category
|
||||
}
|
||||
if payload.Properties.Name != nil {
|
||||
updatedICReq.InfrastructureComponent.Name = *payload.Properties.Name
|
||||
if payload.Status.Name != nil {
|
||||
updatedICReq.InfrastructureComponent.Name = *payload.Status.Name
|
||||
}
|
||||
if payload.Properties.WS_url != nil {
|
||||
updatedICReq.InfrastructureComponent.WebsocketURL = *payload.Properties.WS_url
|
||||
if payload.Status.WS_url != nil {
|
||||
updatedICReq.InfrastructureComponent.WebsocketURL = *payload.Status.WS_url
|
||||
}
|
||||
if payload.Properties.API_url != nil {
|
||||
updatedICReq.InfrastructureComponent.APIURL = *payload.Properties.API_url
|
||||
if payload.Status.API_url != nil {
|
||||
updatedICReq.InfrastructureComponent.APIURL = *payload.Status.API_url
|
||||
}
|
||||
if payload.Properties.Location != nil {
|
||||
//postgres.Jsonb{json.RawMessage(`{"location" : " ` + *payload.Properties.Location + `"}`)}
|
||||
updatedICReq.InfrastructureComponent.Location = *payload.Properties.Location
|
||||
if payload.Status.Location != nil {
|
||||
//postgres.Jsonb{json.RawMessage(`{"location" : " ` + *payload.Status.Location + `"}`)}
|
||||
updatedICReq.InfrastructureComponent.Location = *payload.Status.Location
|
||||
}
|
||||
if payload.Properties.Description != nil {
|
||||
updatedICReq.InfrastructureComponent.Description = *payload.Properties.Description
|
||||
if payload.Status.Description != nil {
|
||||
updatedICReq.InfrastructureComponent.Description = *payload.Status.Description
|
||||
}
|
||||
if payload.Status.Uptime != nil {
|
||||
updatedICReq.InfrastructureComponent.Uptime = *payload.Status.Uptime
|
||||
}
|
||||
// TODO add JSON start parameter scheme
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ type validNewIC struct {
|
|||
Description string `form:"Description" validate:"omitempty"`
|
||||
StartParameterScheme postgres.Jsonb `form:"StartParameterScheme" validate:"omitempty"`
|
||||
ManagedExternally *bool `form:"ManagedExternally" validate:"required"`
|
||||
Uptime float64 `form:"Uptime" validate:"omitempty"`
|
||||
}
|
||||
|
||||
type validUpdatedIC struct {
|
||||
|
@ -60,6 +61,7 @@ type validUpdatedIC struct {
|
|||
Description string `form:"Description" validate:"omitempty"`
|
||||
StartParameterScheme postgres.Jsonb `form:"StartParameterScheme" validate:"omitempty"`
|
||||
ManagedExternally *bool `form:"ManagedExternally" validate:"required"`
|
||||
Uptime float64 `form:"Uptime" validate:"omitempty"`
|
||||
}
|
||||
|
||||
type AddICRequest struct {
|
||||
|
@ -148,6 +150,7 @@ func (r *AddICRequest) createIC(receivedViaAMQP bool) (InfrastructureComponent,
|
|||
s.Description = r.InfrastructureComponent.Description
|
||||
s.StartParameterScheme = r.InfrastructureComponent.StartParameterScheme
|
||||
s.ManagedExternally = *r.InfrastructureComponent.ManagedExternally
|
||||
s.Uptime = -1.0 // no uptime available
|
||||
if r.InfrastructureComponent.State != "" {
|
||||
s.State = r.InfrastructureComponent.State
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue