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:''"`
|
||||
// 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)
|
||||
|
|
|
@ -70,15 +70,19 @@ type ICProperties struct {
|
|||
API_url string `json:"api_url"`
|
||||
Category string `json:"category"`
|
||||
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 {
|
||||
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 {
|
||||
|
|
|
@ -59,6 +59,7 @@ type ICRequest struct {
|
|||
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"`
|
||||
}
|
||||
|
@ -86,7 +87,8 @@ var newIC1 = ICRequest{
|
|||
State: "idle",
|
||||
Location: "k8s",
|
||||
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"}`)},
|
||||
CreateParameterSchema: postgres.Jsonb{json.RawMessage(`{"createprop1" : "a really nice prop"}`)},
|
||||
ManagedExternally: newFalse(),
|
||||
Manager: "7be0322d-354e-431e-84bd-ae4c9633beef",
|
||||
}
|
||||
|
@ -101,7 +103,8 @@ var newIC2 = ICRequest{
|
|||
State: "running",
|
||||
Location: "k8s",
|
||||
Description: "This is a test description",
|
||||
StartParameterSchema: postgres.Jsonb{json.RawMessage(`{"prop1" : "a nice prop"}`)},
|
||||
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",
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ type validNewIC struct {
|
|||
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"`
|
||||
|
@ -60,6 +61,7 @@ type validUpdatedIC struct {
|
|||
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"`
|
||||
|
@ -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
|
||||
|
|
|
@ -67,6 +67,7 @@ type ICRequest struct {
|
|||
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"`
|
||||
}
|
||||
|
||||
|
@ -102,7 +103,8 @@ func addScenarioAndICAndConfig() (scenarioID uint, ICID uint, configID uint) {
|
|||
State: "idle",
|
||||
Location: "k8s",
|
||||
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"}`)},
|
||||
CreateParameterSchema: postgres.Jsonb{json.RawMessage(`{"createprop1" : "a really nice prop"}`)},
|
||||
ManagedExternally: newFalse(),
|
||||
}
|
||||
_, resp, _ := helper.TestEndpoint(router, token,
|
||||
|
|
Loading…
Add table
Reference in a new issue