Add CreateParameterSchema parameter to IC data model and adapt extraction of start and create parameter schemas to new VILLAScontroller protocol #67

This commit is contained in:
Sonja Happ 2021-06-01 11:57:36 +02:00
parent 5e899d50d3
commit b931cdb4f3
5 changed files with 114 additions and 101 deletions

View file

@ -141,8 +141,10 @@ type InfrastructureComponent struct {
Location string `json:"location" gorm:"default:''"`
// Description of the IC
Description string `json:"description" gorm:"default:''"`
// JSON scheme of start parameters for IC
// JSON schema of start parameters for IC
StartParameterSchema postgres.Jsonb `json:"startparameterschema"`
// JSON schema of create parameters for IC
CreateParameterSchema postgres.Jsonb `json:"createparameterschema"`
// raw JSON of last status update
StatusUpdateRaw postgres.Jsonb `json:"statusupdateraw"`
// Boolean indicating if IC is managed externally (via AMQP/ VILLAScontroller)

View file

@ -61,24 +61,28 @@ type ICStatus struct {
}
type ICProperties struct {
UUID string `json:"uuid"`
Name string `json:"name"`
Description string `json:"description"`
Location string `json:"location"`
Owner string `json:"owner"`
WS_url string `json:"ws_url"`
API_url string `json:"api_url"`
Category string `json:"category"`
Type string `json:"type"`
StartParameterSchema json.RawMessage `json:"start_parameter_schema"`
UUID string `json:"uuid"`
Name string `json:"name"`
Description string `json:"description"`
Location string `json:"location"`
Owner string `json:"owner"`
WS_url string `json:"ws_url"`
API_url string `json:"api_url"`
Category string `json:"category"`
Type string `json:"type"`
}
type ICSchema struct {
StartParameterSchema json.RawMessage `json:"start"`
CreateParametersSchema json.RawMessage `json:"create"`
}
type ICUpdate struct {
Status ICStatus `json:"status"`
Properties ICProperties `json:"properties"`
Schema ICSchema `json:"schema"`
When float64 `json:"when"`
Action string `json:"action"`
// TODO add JSON start parameter scheme
}
var client AMQPclient
@ -328,12 +332,11 @@ func createExternalIC(payload ICUpdate, ICUUID string, body []byte) error {
// set managed externally to true because this IC is created via AMQP
newICReq.InfrastructureComponent.ManagedExternally = newTrue()
newICReq.InfrastructureComponent.Manager = payload.Status.ManagedBy
newICReq.InfrastructureComponent.StartParameterSchema = postgres.Jsonb{RawMessage: payload.Properties.StartParameterSchema}
newICReq.InfrastructureComponent.StartParameterSchema = postgres.Jsonb{RawMessage: payload.Schema.StartParameterSchema}
newICReq.InfrastructureComponent.CreateParameterSchema = postgres.Jsonb{RawMessage: payload.Schema.CreateParametersSchema}
// set raw status update if IC
newICReq.InfrastructureComponent.StatusUpdateRaw = postgres.Jsonb{RawMessage: body}
// TODO add JSON start parameter scheme
// Validate the new IC
err := newICReq.validate()
if err != nil {
@ -397,12 +400,11 @@ func (s *InfrastructureComponent) updateExternalIC(payload ICUpdate, body []byte
updatedICReq.InfrastructureComponent.Location = payload.Properties.Location
updatedICReq.InfrastructureComponent.Description = payload.Properties.Description
updatedICReq.InfrastructureComponent.Manager = payload.Status.ManagedBy
updatedICReq.InfrastructureComponent.StartParameterSchema = postgres.Jsonb{RawMessage: payload.Properties.StartParameterSchema}
updatedICReq.InfrastructureComponent.StartParameterSchema = postgres.Jsonb{RawMessage: payload.Schema.StartParameterSchema}
updatedICReq.InfrastructureComponent.CreateParameterSchema = postgres.Jsonb{RawMessage: payload.Schema.CreateParametersSchema}
// set raw status update if IC
updatedICReq.InfrastructureComponent.StatusUpdateRaw = postgres.Jsonb{RawMessage: body}
// TODO add JSON start parameter scheme
// Validate the updated IC
err := updatedICReq.validate()
if err != nil {

View file

@ -49,18 +49,19 @@ var api *gin.RouterGroup
var waitingTime time.Duration = 1
type ICRequest struct {
UUID string `json:"uuid,omitempty"`
WebsocketURL string `json:"websocketurl,omitempty"`
APIURL string `json:"apiurl,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Category string `json:"category,omitempty"`
State string `json:"state,omitempty"`
Location string `json:"location,omitempty"`
Description string `json:"description,omitempty"`
StartParameterSchema postgres.Jsonb `json:"startparameterschema,omitempty"`
ManagedExternally *bool `json:"managedexternally"`
Manager string `json:"manager,omitempty"`
UUID string `json:"uuid,omitempty"`
WebsocketURL string `json:"websocketurl,omitempty"`
APIURL string `json:"apiurl,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Category string `json:"category,omitempty"`
State string `json:"state,omitempty"`
Location string `json:"location,omitempty"`
Description string `json:"description,omitempty"`
StartParameterSchema postgres.Jsonb `json:"startparameterschema,omitempty"`
CreateParameterSchema postgres.Jsonb `json:"createparameterschema,omitempty"`
ManagedExternally *bool `json:"managedexternally"`
Manager string `json:"manager,omitempty"`
}
type ScenarioRequest struct {
@ -77,33 +78,35 @@ type ConfigRequest struct {
}
var newIC1 = ICRequest{
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
WebsocketURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/ws_sig",
APIURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/api/v2",
Type: "villas-node",
Name: "ACS Demo Signals",
Category: "gateway",
State: "idle",
Location: "k8s",
Description: "A signal generator for testing purposes",
StartParameterSchema: postgres.Jsonb{json.RawMessage(`{"prop1" : "a nice prop"}`)},
ManagedExternally: newFalse(),
Manager: "7be0322d-354e-431e-84bd-ae4c9633beef",
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
WebsocketURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/ws_sig",
APIURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/api/v2",
Type: "villas-node",
Name: "ACS Demo Signals",
Category: "gateway",
State: "idle",
Location: "k8s",
Description: "A signal generator for testing purposes",
StartParameterSchema: postgres.Jsonb{json.RawMessage(`{"startprop1" : "a nice prop"}`)},
CreateParameterSchema: postgres.Jsonb{json.RawMessage(`{"createprop1" : "a really nice prop"}`)},
ManagedExternally: newFalse(),
Manager: "7be0322d-354e-431e-84bd-ae4c9633beef",
}
var newIC2 = ICRequest{
UUID: "4854af30-325f-44a5-ad59-b67b2597de68",
WebsocketURL: "xxx.yyy.zzz.aaa",
APIURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/api/v2",
Type: "dpsim",
Name: "Test DPsim Simulator",
Category: "simulator",
State: "running",
Location: "k8s",
Description: "This is a test description",
StartParameterSchema: postgres.Jsonb{json.RawMessage(`{"prop1" : "a nice prop"}`)},
ManagedExternally: newTrue(),
Manager: "4854af30-325f-44a5-ad59-b67b2597de99",
UUID: "4854af30-325f-44a5-ad59-b67b2597de68",
WebsocketURL: "xxx.yyy.zzz.aaa",
APIURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/api/v2",
Type: "dpsim",
Name: "Test DPsim Simulator",
Category: "simulator",
State: "running",
Location: "k8s",
Description: "This is a test description",
StartParameterSchema: postgres.Jsonb{json.RawMessage(`{"startprop1" : "a nice prop"}`)},
CreateParameterSchema: postgres.Jsonb{json.RawMessage(`{"createprop1" : "a really nice prop"}`)},
ManagedExternally: newTrue(),
Manager: "4854af30-325f-44a5-ad59-b67b2597de99",
}
func TestMain(m *testing.M) {

View file

@ -33,36 +33,38 @@ import (
var validate *validator.Validate
type validNewIC struct {
UUID string `form:"UUID" validate:"omitempty"`
WebsocketURL string `form:"WebsocketURL" validate:"omitempty"`
APIURL string `form:"APIURL" validate:"omitempty"`
Type string `form:"Type" validate:"required"`
Name string `form:"Name" validate:"required"`
Category string `form:"Category" validate:"required"`
State string `form:"State" validate:"omitempty"`
Location string `form:"Location" validate:"omitempty"`
Description string `form:"Description" validate:"omitempty"`
StartParameterSchema postgres.Jsonb `form:"StartParameterSchema" validate:"omitempty"`
StatusUpdateRaw postgres.Jsonb `form:"StatusUpdateRaw" validate:"omitempty"`
ManagedExternally *bool `form:"ManagedExternally" validate:"required"`
Manager string `form:"Manager" validate:"omitempty"`
Uptime float64 `form:"Uptime" validate:"omitempty"`
UUID string `form:"UUID" validate:"omitempty"`
WebsocketURL string `form:"WebsocketURL" validate:"omitempty"`
APIURL string `form:"APIURL" validate:"omitempty"`
Type string `form:"Type" validate:"required"`
Name string `form:"Name" validate:"required"`
Category string `form:"Category" validate:"required"`
State string `form:"State" validate:"omitempty"`
Location string `form:"Location" validate:"omitempty"`
Description string `form:"Description" validate:"omitempty"`
StartParameterSchema postgres.Jsonb `form:"StartParameterSchema" validate:"omitempty"`
CreateParameterSchema postgres.Jsonb `form:"CreateParameterSchema" validate:"omitempty"`
StatusUpdateRaw postgres.Jsonb `form:"StatusUpdateRaw" validate:"omitempty"`
ManagedExternally *bool `form:"ManagedExternally" validate:"required"`
Manager string `form:"Manager" validate:"omitempty"`
Uptime float64 `form:"Uptime" validate:"omitempty"`
}
type validUpdatedIC struct {
UUID string `form:"UUID" validate:"omitempty"`
WebsocketURL string `form:"WebsocketURL" validate:"omitempty"`
APIURL string `form:"APIURL" validate:"omitempty"`
Type string `form:"Type" validate:"omitempty"`
Name string `form:"Name" validate:"omitempty"`
Category string `form:"Category" validate:"omitempty"`
State string `form:"State" validate:"omitempty"`
Location string `form:"Location" validate:"omitempty"`
Description string `form:"Description" validate:"omitempty"`
StartParameterSchema postgres.Jsonb `form:"StartParameterSchema" validate:"omitempty"`
StatusUpdateRaw postgres.Jsonb `form:"StatusUpdateRaw" validate:"omitempty"`
Manager string `form:"Manager" validate:"omitempty"`
Uptime float64 `form:"Uptime" validate:"omitempty"`
UUID string `form:"UUID" validate:"omitempty"`
WebsocketURL string `form:"WebsocketURL" validate:"omitempty"`
APIURL string `form:"APIURL" validate:"omitempty"`
Type string `form:"Type" validate:"omitempty"`
Name string `form:"Name" validate:"omitempty"`
Category string `form:"Category" validate:"omitempty"`
State string `form:"State" validate:"omitempty"`
Location string `form:"Location" validate:"omitempty"`
Description string `form:"Description" validate:"omitempty"`
StartParameterSchema postgres.Jsonb `form:"StartParameterSchema" validate:"omitempty"`
CreateParameterSchema postgres.Jsonb `form:"CreateParameterSchema" validate:"omitempty"`
StatusUpdateRaw postgres.Jsonb `form:"StatusUpdateRaw" validate:"omitempty"`
Manager string `form:"Manager" validate:"omitempty"`
Uptime float64 `form:"Uptime" validate:"omitempty"`
}
type AddICRequest struct {
@ -129,6 +131,7 @@ func (r *AddICRequest) createIC() (InfrastructureComponent, error) {
s.Location = r.InfrastructureComponent.Location
s.Description = r.InfrastructureComponent.Description
s.StartParameterSchema = r.InfrastructureComponent.StartParameterSchema
s.CreateParameterSchema = r.InfrastructureComponent.CreateParameterSchema
s.StatusUpdateRaw = r.InfrastructureComponent.StatusUpdateRaw
s.ManagedExternally = *r.InfrastructureComponent.ManagedExternally
s.Manager = r.InfrastructureComponent.Manager
@ -159,6 +162,7 @@ func (r *UpdateICRequest) updatedIC(oldIC InfrastructureComponent) Infrastructur
s.Uptime = math.Round(r.InfrastructureComponent.Uptime) // round required for backward compatibility of data model
s.Manager = r.InfrastructureComponent.Manager
s.StartParameterSchema = r.InfrastructureComponent.StartParameterSchema
s.CreateParameterSchema = r.InfrastructureComponent.CreateParameterSchema
s.StatusUpdateRaw = r.InfrastructureComponent.StatusUpdateRaw
// set last update time

View file

@ -58,16 +58,17 @@ type ConfigRequest struct {
}
type ICRequest struct {
UUID string `json:"uuid,omitempty"`
WebsocketURL string `json:"websocketurl,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Category string `json:"category,omitempty"`
State string `json:"state,omitempty"`
Location string `json:"location,omitempty"`
Description string `json:"description,omitempty"`
StartParameterSchema postgres.Jsonb `json:"startparameterschema,omitempty"`
ManagedExternally *bool `json:"managedexternally,omitempty"`
UUID string `json:"uuid,omitempty"`
WebsocketURL string `json:"websocketurl,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Category string `json:"category,omitempty"`
State string `json:"state,omitempty"`
Location string `json:"location,omitempty"`
Description string `json:"description,omitempty"`
StartParameterSchema postgres.Jsonb `json:"startparameterschema,omitempty"`
CreateParameterSchema postgres.Jsonb `json:"createparameterschema,omitempty"`
ManagedExternally *bool `json:"managedexternally,omitempty"`
}
type ScenarioRequest struct {
@ -94,16 +95,17 @@ func addScenarioAndICAndConfig() (scenarioID uint, ICID uint, configID uint) {
// POST $newICA
newICA := ICRequest{
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
WebsocketURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/ws_sig",
Type: "villas-node",
Name: "ACS Demo Signals",
Category: "gateway",
State: "idle",
Location: "k8s",
Description: "A signal generator for testing purposes",
StartParameterSchema: postgres.Jsonb{json.RawMessage(`{"prop1" : "a nice prop"}`)},
ManagedExternally: newFalse(),
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
WebsocketURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/ws_sig",
Type: "villas-node",
Name: "ACS Demo Signals",
Category: "gateway",
State: "idle",
Location: "k8s",
Description: "A signal generator for testing purposes",
StartParameterSchema: postgres.Jsonb{json.RawMessage(`{"startprop1" : "a nice prop"}`)},
CreateParameterSchema: postgres.Jsonb{json.RawMessage(`{"createprop1" : "a really nice prop"}`)},
ManagedExternally: newFalse(),
}
_, resp, _ := helper.TestEndpoint(router, token,
"/api/v2/ic", "POST", helper.KeyModels{"ic": newICA})