mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
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:
parent
5e899d50d3
commit
b931cdb4f3
5 changed files with 114 additions and 101 deletions
|
@ -141,8 +141,10 @@ type InfrastructureComponent struct {
|
||||||
Location string `json:"location" gorm:"default:''"`
|
Location string `json:"location" gorm:"default:''"`
|
||||||
// Description of the IC
|
// Description of the IC
|
||||||
Description string `json:"description" gorm:"default:''"`
|
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"`
|
StartParameterSchema postgres.Jsonb `json:"startparameterschema"`
|
||||||
|
// JSON schema of create parameters for IC
|
||||||
|
CreateParameterSchema postgres.Jsonb `json:"createparameterschema"`
|
||||||
// raw JSON of last status update
|
// raw JSON of last status update
|
||||||
StatusUpdateRaw postgres.Jsonb `json:"statusupdateraw"`
|
StatusUpdateRaw postgres.Jsonb `json:"statusupdateraw"`
|
||||||
// Boolean indicating if IC is managed externally (via AMQP/ VILLAScontroller)
|
// Boolean indicating if IC is managed externally (via AMQP/ VILLAScontroller)
|
||||||
|
|
|
@ -61,24 +61,28 @@ type ICStatus struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ICProperties struct {
|
type ICProperties struct {
|
||||||
UUID string `json:"uuid"`
|
UUID string `json:"uuid"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
Owner string `json:"owner"`
|
Owner string `json:"owner"`
|
||||||
WS_url string `json:"ws_url"`
|
WS_url string `json:"ws_url"`
|
||||||
API_url string `json:"api_url"`
|
API_url string `json:"api_url"`
|
||||||
Category string `json:"category"`
|
Category string `json:"category"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
StartParameterSchema json.RawMessage `json:"start_parameter_schema"`
|
}
|
||||||
|
|
||||||
|
type ICSchema struct {
|
||||||
|
StartParameterSchema json.RawMessage `json:"start"`
|
||||||
|
CreateParametersSchema json.RawMessage `json:"create"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ICUpdate struct {
|
type ICUpdate struct {
|
||||||
Status ICStatus `json:"status"`
|
Status ICStatus `json:"status"`
|
||||||
Properties ICProperties `json:"properties"`
|
Properties ICProperties `json:"properties"`
|
||||||
|
Schema ICSchema `json:"schema"`
|
||||||
When float64 `json:"when"`
|
When float64 `json:"when"`
|
||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
// TODO add JSON start parameter scheme
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var client AMQPclient
|
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
|
// set managed externally to true because this IC is created via AMQP
|
||||||
newICReq.InfrastructureComponent.ManagedExternally = newTrue()
|
newICReq.InfrastructureComponent.ManagedExternally = newTrue()
|
||||||
newICReq.InfrastructureComponent.Manager = payload.Status.ManagedBy
|
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
|
// set raw status update if IC
|
||||||
newICReq.InfrastructureComponent.StatusUpdateRaw = postgres.Jsonb{RawMessage: body}
|
newICReq.InfrastructureComponent.StatusUpdateRaw = postgres.Jsonb{RawMessage: body}
|
||||||
|
|
||||||
// TODO add JSON start parameter scheme
|
|
||||||
|
|
||||||
// Validate the new IC
|
// Validate the new IC
|
||||||
err := newICReq.validate()
|
err := newICReq.validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -397,12 +400,11 @@ func (s *InfrastructureComponent) updateExternalIC(payload ICUpdate, body []byte
|
||||||
updatedICReq.InfrastructureComponent.Location = payload.Properties.Location
|
updatedICReq.InfrastructureComponent.Location = payload.Properties.Location
|
||||||
updatedICReq.InfrastructureComponent.Description = payload.Properties.Description
|
updatedICReq.InfrastructureComponent.Description = payload.Properties.Description
|
||||||
updatedICReq.InfrastructureComponent.Manager = payload.Status.ManagedBy
|
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
|
// set raw status update if IC
|
||||||
updatedICReq.InfrastructureComponent.StatusUpdateRaw = postgres.Jsonb{RawMessage: body}
|
updatedICReq.InfrastructureComponent.StatusUpdateRaw = postgres.Jsonb{RawMessage: body}
|
||||||
|
|
||||||
// TODO add JSON start parameter scheme
|
|
||||||
|
|
||||||
// Validate the updated IC
|
// Validate the updated IC
|
||||||
err := updatedICReq.validate()
|
err := updatedICReq.validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -49,18 +49,19 @@ var api *gin.RouterGroup
|
||||||
var waitingTime time.Duration = 1
|
var waitingTime time.Duration = 1
|
||||||
|
|
||||||
type ICRequest struct {
|
type ICRequest struct {
|
||||||
UUID string `json:"uuid,omitempty"`
|
UUID string `json:"uuid,omitempty"`
|
||||||
WebsocketURL string `json:"websocketurl,omitempty"`
|
WebsocketURL string `json:"websocketurl,omitempty"`
|
||||||
APIURL string `json:"apiurl,omitempty"`
|
APIURL string `json:"apiurl,omitempty"`
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Category string `json:"category,omitempty"`
|
Category string `json:"category,omitempty"`
|
||||||
State string `json:"state,omitempty"`
|
State string `json:"state,omitempty"`
|
||||||
Location string `json:"location,omitempty"`
|
Location string `json:"location,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
StartParameterSchema postgres.Jsonb `json:"startparameterschema,omitempty"`
|
StartParameterSchema postgres.Jsonb `json:"startparameterschema,omitempty"`
|
||||||
ManagedExternally *bool `json:"managedexternally"`
|
CreateParameterSchema postgres.Jsonb `json:"createparameterschema,omitempty"`
|
||||||
Manager string `json:"manager,omitempty"`
|
ManagedExternally *bool `json:"managedexternally"`
|
||||||
|
Manager string `json:"manager,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ScenarioRequest struct {
|
type ScenarioRequest struct {
|
||||||
|
@ -77,33 +78,35 @@ type ConfigRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var newIC1 = ICRequest{
|
var newIC1 = ICRequest{
|
||||||
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
|
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
|
||||||
WebsocketURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/ws_sig",
|
WebsocketURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/ws_sig",
|
||||||
APIURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/api/v2",
|
APIURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/api/v2",
|
||||||
Type: "villas-node",
|
Type: "villas-node",
|
||||||
Name: "ACS Demo Signals",
|
Name: "ACS Demo Signals",
|
||||||
Category: "gateway",
|
Category: "gateway",
|
||||||
State: "idle",
|
State: "idle",
|
||||||
Location: "k8s",
|
Location: "k8s",
|
||||||
Description: "A signal generator for testing purposes",
|
Description: "A signal generator for testing purposes",
|
||||||
StartParameterSchema: postgres.Jsonb{json.RawMessage(`{"prop1" : "a nice prop"}`)},
|
StartParameterSchema: postgres.Jsonb{json.RawMessage(`{"startprop1" : "a nice prop"}`)},
|
||||||
ManagedExternally: newFalse(),
|
CreateParameterSchema: postgres.Jsonb{json.RawMessage(`{"createprop1" : "a really nice prop"}`)},
|
||||||
Manager: "7be0322d-354e-431e-84bd-ae4c9633beef",
|
ManagedExternally: newFalse(),
|
||||||
|
Manager: "7be0322d-354e-431e-84bd-ae4c9633beef",
|
||||||
}
|
}
|
||||||
|
|
||||||
var newIC2 = ICRequest{
|
var newIC2 = ICRequest{
|
||||||
UUID: "4854af30-325f-44a5-ad59-b67b2597de68",
|
UUID: "4854af30-325f-44a5-ad59-b67b2597de68",
|
||||||
WebsocketURL: "xxx.yyy.zzz.aaa",
|
WebsocketURL: "xxx.yyy.zzz.aaa",
|
||||||
APIURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/api/v2",
|
APIURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/api/v2",
|
||||||
Type: "dpsim",
|
Type: "dpsim",
|
||||||
Name: "Test DPsim Simulator",
|
Name: "Test DPsim Simulator",
|
||||||
Category: "simulator",
|
Category: "simulator",
|
||||||
State: "running",
|
State: "running",
|
||||||
Location: "k8s",
|
Location: "k8s",
|
||||||
Description: "This is a test description",
|
Description: "This is a test description",
|
||||||
StartParameterSchema: postgres.Jsonb{json.RawMessage(`{"prop1" : "a nice prop"}`)},
|
StartParameterSchema: postgres.Jsonb{json.RawMessage(`{"startprop1" : "a nice prop"}`)},
|
||||||
ManagedExternally: newTrue(),
|
CreateParameterSchema: postgres.Jsonb{json.RawMessage(`{"createprop1" : "a really nice prop"}`)},
|
||||||
Manager: "4854af30-325f-44a5-ad59-b67b2597de99",
|
ManagedExternally: newTrue(),
|
||||||
|
Manager: "4854af30-325f-44a5-ad59-b67b2597de99",
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
|
|
@ -33,36 +33,38 @@ import (
|
||||||
var validate *validator.Validate
|
var validate *validator.Validate
|
||||||
|
|
||||||
type validNewIC struct {
|
type validNewIC struct {
|
||||||
UUID string `form:"UUID" validate:"omitempty"`
|
UUID string `form:"UUID" validate:"omitempty"`
|
||||||
WebsocketURL string `form:"WebsocketURL" validate:"omitempty"`
|
WebsocketURL string `form:"WebsocketURL" validate:"omitempty"`
|
||||||
APIURL string `form:"APIURL" validate:"omitempty"`
|
APIURL string `form:"APIURL" validate:"omitempty"`
|
||||||
Type string `form:"Type" validate:"required"`
|
Type string `form:"Type" validate:"required"`
|
||||||
Name string `form:"Name" validate:"required"`
|
Name string `form:"Name" validate:"required"`
|
||||||
Category string `form:"Category" validate:"required"`
|
Category string `form:"Category" validate:"required"`
|
||||||
State string `form:"State" validate:"omitempty"`
|
State string `form:"State" validate:"omitempty"`
|
||||||
Location string `form:"Location" validate:"omitempty"`
|
Location string `form:"Location" validate:"omitempty"`
|
||||||
Description string `form:"Description" validate:"omitempty"`
|
Description string `form:"Description" validate:"omitempty"`
|
||||||
StartParameterSchema postgres.Jsonb `form:"StartParameterSchema" validate:"omitempty"`
|
StartParameterSchema postgres.Jsonb `form:"StartParameterSchema" validate:"omitempty"`
|
||||||
StatusUpdateRaw postgres.Jsonb `form:"StatusUpdateRaw" validate:"omitempty"`
|
CreateParameterSchema postgres.Jsonb `form:"CreateParameterSchema" validate:"omitempty"`
|
||||||
ManagedExternally *bool `form:"ManagedExternally" validate:"required"`
|
StatusUpdateRaw postgres.Jsonb `form:"StatusUpdateRaw" validate:"omitempty"`
|
||||||
Manager string `form:"Manager" validate:"omitempty"`
|
ManagedExternally *bool `form:"ManagedExternally" validate:"required"`
|
||||||
Uptime float64 `form:"Uptime" validate:"omitempty"`
|
Manager string `form:"Manager" validate:"omitempty"`
|
||||||
|
Uptime float64 `form:"Uptime" validate:"omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type validUpdatedIC struct {
|
type validUpdatedIC struct {
|
||||||
UUID string `form:"UUID" validate:"omitempty"`
|
UUID string `form:"UUID" validate:"omitempty"`
|
||||||
WebsocketURL string `form:"WebsocketURL" validate:"omitempty"`
|
WebsocketURL string `form:"WebsocketURL" validate:"omitempty"`
|
||||||
APIURL string `form:"APIURL" validate:"omitempty"`
|
APIURL string `form:"APIURL" validate:"omitempty"`
|
||||||
Type string `form:"Type" validate:"omitempty"`
|
Type string `form:"Type" validate:"omitempty"`
|
||||||
Name string `form:"Name" validate:"omitempty"`
|
Name string `form:"Name" validate:"omitempty"`
|
||||||
Category string `form:"Category" validate:"omitempty"`
|
Category string `form:"Category" validate:"omitempty"`
|
||||||
State string `form:"State" validate:"omitempty"`
|
State string `form:"State" validate:"omitempty"`
|
||||||
Location string `form:"Location" validate:"omitempty"`
|
Location string `form:"Location" validate:"omitempty"`
|
||||||
Description string `form:"Description" validate:"omitempty"`
|
Description string `form:"Description" validate:"omitempty"`
|
||||||
StartParameterSchema postgres.Jsonb `form:"StartParameterSchema" validate:"omitempty"`
|
StartParameterSchema postgres.Jsonb `form:"StartParameterSchema" validate:"omitempty"`
|
||||||
StatusUpdateRaw postgres.Jsonb `form:"StatusUpdateRaw" validate:"omitempty"`
|
CreateParameterSchema postgres.Jsonb `form:"CreateParameterSchema" validate:"omitempty"`
|
||||||
Manager string `form:"Manager" validate:"omitempty"`
|
StatusUpdateRaw postgres.Jsonb `form:"StatusUpdateRaw" validate:"omitempty"`
|
||||||
Uptime float64 `form:"Uptime" validate:"omitempty"`
|
Manager string `form:"Manager" validate:"omitempty"`
|
||||||
|
Uptime float64 `form:"Uptime" validate:"omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddICRequest struct {
|
type AddICRequest struct {
|
||||||
|
@ -129,6 +131,7 @@ func (r *AddICRequest) createIC() (InfrastructureComponent, error) {
|
||||||
s.Location = r.InfrastructureComponent.Location
|
s.Location = r.InfrastructureComponent.Location
|
||||||
s.Description = r.InfrastructureComponent.Description
|
s.Description = r.InfrastructureComponent.Description
|
||||||
s.StartParameterSchema = r.InfrastructureComponent.StartParameterSchema
|
s.StartParameterSchema = r.InfrastructureComponent.StartParameterSchema
|
||||||
|
s.CreateParameterSchema = r.InfrastructureComponent.CreateParameterSchema
|
||||||
s.StatusUpdateRaw = r.InfrastructureComponent.StatusUpdateRaw
|
s.StatusUpdateRaw = r.InfrastructureComponent.StatusUpdateRaw
|
||||||
s.ManagedExternally = *r.InfrastructureComponent.ManagedExternally
|
s.ManagedExternally = *r.InfrastructureComponent.ManagedExternally
|
||||||
s.Manager = r.InfrastructureComponent.Manager
|
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.Uptime = math.Round(r.InfrastructureComponent.Uptime) // round required for backward compatibility of data model
|
||||||
s.Manager = r.InfrastructureComponent.Manager
|
s.Manager = r.InfrastructureComponent.Manager
|
||||||
s.StartParameterSchema = r.InfrastructureComponent.StartParameterSchema
|
s.StartParameterSchema = r.InfrastructureComponent.StartParameterSchema
|
||||||
|
s.CreateParameterSchema = r.InfrastructureComponent.CreateParameterSchema
|
||||||
s.StatusUpdateRaw = r.InfrastructureComponent.StatusUpdateRaw
|
s.StatusUpdateRaw = r.InfrastructureComponent.StatusUpdateRaw
|
||||||
|
|
||||||
// set last update time
|
// set last update time
|
||||||
|
|
|
@ -58,16 +58,17 @@ type ConfigRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ICRequest struct {
|
type ICRequest struct {
|
||||||
UUID string `json:"uuid,omitempty"`
|
UUID string `json:"uuid,omitempty"`
|
||||||
WebsocketURL string `json:"websocketurl,omitempty"`
|
WebsocketURL string `json:"websocketurl,omitempty"`
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Category string `json:"category,omitempty"`
|
Category string `json:"category,omitempty"`
|
||||||
State string `json:"state,omitempty"`
|
State string `json:"state,omitempty"`
|
||||||
Location string `json:"location,omitempty"`
|
Location string `json:"location,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
StartParameterSchema postgres.Jsonb `json:"startparameterschema,omitempty"`
|
StartParameterSchema postgres.Jsonb `json:"startparameterschema,omitempty"`
|
||||||
ManagedExternally *bool `json:"managedexternally,omitempty"`
|
CreateParameterSchema postgres.Jsonb `json:"createparameterschema,omitempty"`
|
||||||
|
ManagedExternally *bool `json:"managedexternally,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ScenarioRequest struct {
|
type ScenarioRequest struct {
|
||||||
|
@ -94,16 +95,17 @@ func addScenarioAndICAndConfig() (scenarioID uint, ICID uint, configID uint) {
|
||||||
|
|
||||||
// POST $newICA
|
// POST $newICA
|
||||||
newICA := ICRequest{
|
newICA := ICRequest{
|
||||||
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
|
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
|
||||||
WebsocketURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/ws_sig",
|
WebsocketURL: "https://villas.k8s.eonerc.rwth-aachen.de/ws/ws_sig",
|
||||||
Type: "villas-node",
|
Type: "villas-node",
|
||||||
Name: "ACS Demo Signals",
|
Name: "ACS Demo Signals",
|
||||||
Category: "gateway",
|
Category: "gateway",
|
||||||
State: "idle",
|
State: "idle",
|
||||||
Location: "k8s",
|
Location: "k8s",
|
||||||
Description: "A signal generator for testing purposes",
|
Description: "A signal generator for testing purposes",
|
||||||
StartParameterSchema: postgres.Jsonb{json.RawMessage(`{"prop1" : "a nice prop"}`)},
|
StartParameterSchema: postgres.Jsonb{json.RawMessage(`{"startprop1" : "a nice prop"}`)},
|
||||||
ManagedExternally: newFalse(),
|
CreateParameterSchema: postgres.Jsonb{json.RawMessage(`{"createprop1" : "a really nice prop"}`)},
|
||||||
|
ManagedExternally: newFalse(),
|
||||||
}
|
}
|
||||||
_, resp, _ := helper.TestEndpoint(router, token,
|
_, resp, _ := helper.TestEndpoint(router, token,
|
||||||
"/api/v2/ic", "POST", helper.KeyModels{"ic": newICA})
|
"/api/v2/ic", "POST", helper.KeyModels{"ic": newICA})
|
||||||
|
|
Loading…
Add table
Reference in a new issue