mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
modify model of infrastructure component; add name, type, and category as top level parameters; fix testing of packages accordingly
This commit is contained in:
parent
e6b6a0f970
commit
4a58143a6e
10 changed files with 93 additions and 37 deletions
|
@ -133,7 +133,7 @@ func ConnectAMQP(uri string) error {
|
|||
|
||||
err = db.Model(&sToBeUpdated).Updates(map[string]interface{}{
|
||||
"Host": gjson.Get(content, "host"),
|
||||
"Modeltype": gjson.Get(content, "model"),
|
||||
"Type": gjson.Get(content, "model"),
|
||||
"Uptime": gjson.Get(content, "uptime"),
|
||||
"State": gjson.Get(content, "state"),
|
||||
"StateUpdateAt": time.Now().String(),
|
||||
|
|
|
@ -195,7 +195,7 @@ func TestICAssociations(t *testing.T) {
|
|||
|
||||
var ic1 InfrastructureComponent
|
||||
assert.NoError(t, DBpool.Find(&ic1, 1).Error, fmt.Sprintf("Find InfrastructureComponent with ID=1"))
|
||||
assert.EqualValues(t, "Host_A", ic1.Host)
|
||||
assert.EqualValues(t, "xxx.yyy.zzz.aaa", ic1.Host)
|
||||
|
||||
// Get Component Configurations of ic1
|
||||
var configs []ComponentConfiguration
|
||||
|
|
|
@ -116,10 +116,14 @@ type InfrastructureComponent struct {
|
|||
Model
|
||||
// UUID of the IC
|
||||
UUID string `json:"uuid" gorm:"not null"`
|
||||
// Name of the IC
|
||||
Name string `json:"name" gorm:"default:''"`
|
||||
// Host if the IC
|
||||
Host string `json:"host" gorm:"default:''"`
|
||||
// Model type supported by the IC
|
||||
Modeltype string `json:"modelType" gorm:"default:''"`
|
||||
// Category of IC (simulator, gateway, database, etc.)
|
||||
Category string `json:"category" gorm:"default:''"`
|
||||
// Type of IC (RTDS, VILLASnode, RTDS, etc.)
|
||||
Type string `json:"type" gorm:"default:''"`
|
||||
// Uptime of the IC
|
||||
Uptime int `json:"uptime" gorm:"default:0"`
|
||||
// State of the IC
|
||||
|
|
|
@ -95,13 +95,15 @@ var newUserC = UserRequest{
|
|||
|
||||
// Infrastructure components
|
||||
|
||||
var propertiesA = json.RawMessage(`{"name" : "DPsim simulator", "category" : "Simulator", "location" : "ACSlab", "type": "DPsim"}`)
|
||||
var propertiesB = json.RawMessage(`{"name" : "VILLASnode gateway", "category" : "Gateway", "location" : "ACSlab", "type": "VILLASnode"}`)
|
||||
var propertiesA = json.RawMessage(`{"location" : "ACSlab"}`)
|
||||
var propertiesB = json.RawMessage(`{"location" : "ACSlab"}`)
|
||||
|
||||
var ICA = InfrastructureComponent{
|
||||
UUID: "4854af30-325f-44a5-ad59-b67b2597de68",
|
||||
Host: "Host_A",
|
||||
Modeltype: "ModelTypeA",
|
||||
Host: "xxx.yyy.zzz.aaa",
|
||||
Type: "DPsim",
|
||||
Category: "Simulator",
|
||||
Name: "Test DPsim Simulator",
|
||||
Uptime: 0,
|
||||
State: "running",
|
||||
StateUpdateAt: time.Now().String(),
|
||||
|
@ -111,8 +113,10 @@ var ICA = InfrastructureComponent{
|
|||
|
||||
var ICB = InfrastructureComponent{
|
||||
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
|
||||
Host: "Host_B",
|
||||
Modeltype: "ModelTypeB",
|
||||
Host: "xxx.yyy.zzz.bbb",
|
||||
Type: "VILLASnode",
|
||||
Category: "Gateway",
|
||||
Name: "Test VILLASnode Gateway",
|
||||
Uptime: 0,
|
||||
State: "idle",
|
||||
StateUpdateAt: time.Now().String(),
|
||||
|
|
|
@ -3660,7 +3660,7 @@ var doc = `{
|
|||
"type": "object",
|
||||
"required": [
|
||||
"Host",
|
||||
"Modeltype",
|
||||
"Type",
|
||||
"Properties",
|
||||
"UUID"
|
||||
],
|
||||
|
@ -3668,7 +3668,7 @@ var doc = `{
|
|||
"Host": {
|
||||
"type": "string"
|
||||
},
|
||||
"Modeltype": {
|
||||
"Type": {
|
||||
"type": "string"
|
||||
},
|
||||
"Properties": {
|
||||
|
@ -3688,7 +3688,7 @@ var doc = `{
|
|||
"Host": {
|
||||
"type": "string"
|
||||
},
|
||||
"Modeltype": {
|
||||
"Type": {
|
||||
"type": "string"
|
||||
},
|
||||
"Properties": {
|
||||
|
|
|
@ -51,7 +51,9 @@ type ConfigRequest struct {
|
|||
type ICRequest struct {
|
||||
UUID string `json:"uuid,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Modeltype string `json:"modelType,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Properties postgres.Jsonb `json:"properties,omitempty"`
|
||||
}
|
||||
|
@ -72,7 +74,9 @@ func addScenarioAndIC() (scenarioID uint, ICID uint) {
|
|||
newICA := ICRequest{
|
||||
UUID: database.ICA.UUID,
|
||||
Host: database.ICA.Host,
|
||||
Modeltype: database.ICA.Modeltype,
|
||||
Type: database.ICA.Type,
|
||||
Name: database.ICA.Name,
|
||||
Category: database.ICA.Category,
|
||||
State: database.ICA.State,
|
||||
Properties: database.ICA.Properties,
|
||||
}
|
||||
|
@ -86,7 +90,9 @@ func addScenarioAndIC() (scenarioID uint, ICID uint) {
|
|||
newICB := ICRequest{
|
||||
UUID: database.ICB.UUID,
|
||||
Host: database.ICB.Host,
|
||||
Modeltype: database.ICB.Modeltype,
|
||||
Type: database.ICB.Type,
|
||||
Name: database.ICB.Name,
|
||||
Category: database.ICB.Category,
|
||||
State: database.ICB.State,
|
||||
Properties: database.ICB.Properties,
|
||||
}
|
||||
|
|
|
@ -57,7 +57,9 @@ type ConfigRequest struct {
|
|||
type ICRequest struct {
|
||||
UUID string `json:"uuid,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Modeltype string `json:"modelType,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Properties postgres.Jsonb `json:"properties,omitempty"`
|
||||
}
|
||||
|
@ -99,7 +101,9 @@ func addScenarioAndICAndConfigAndDashboardAndWidget() (scenarioID uint, ICID uin
|
|||
newICA := ICRequest{
|
||||
UUID: database.ICA.UUID,
|
||||
Host: database.ICA.Host,
|
||||
Modeltype: database.ICA.Modeltype,
|
||||
Type: database.ICA.Type,
|
||||
Name: database.ICA.Name,
|
||||
Category: database.ICA.Category,
|
||||
State: database.ICA.State,
|
||||
Properties: database.ICA.Properties,
|
||||
}
|
||||
|
|
|
@ -41,7 +41,9 @@ var router *gin.Engine
|
|||
type ICRequest struct {
|
||||
UUID string `json:"uuid,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Modeltype string `json:"modelType,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Properties postgres.Jsonb `json:"properties,omitempty"`
|
||||
}
|
||||
|
@ -99,7 +101,9 @@ func TestAddICAsAdmin(t *testing.T) {
|
|||
newIC := ICRequest{
|
||||
UUID: database.ICA.UUID,
|
||||
Host: database.ICA.Host,
|
||||
Modeltype: database.ICA.Modeltype,
|
||||
Type: database.ICA.Type,
|
||||
Name: database.ICA.Name,
|
||||
Category: database.ICA.Category,
|
||||
State: database.ICA.State,
|
||||
Properties: database.ICA.Properties,
|
||||
}
|
||||
|
@ -149,7 +153,9 @@ func TestAddICAsUser(t *testing.T) {
|
|||
newIC := ICRequest{
|
||||
UUID: database.ICA.UUID,
|
||||
Host: database.ICA.Host,
|
||||
Modeltype: database.ICA.Modeltype,
|
||||
Type: database.ICA.Type,
|
||||
Name: database.ICA.Name,
|
||||
Category: database.ICA.Category,
|
||||
State: database.ICA.State,
|
||||
Properties: database.ICA.Properties,
|
||||
}
|
||||
|
@ -176,7 +182,9 @@ func TestUpdateICAsAdmin(t *testing.T) {
|
|||
newIC := ICRequest{
|
||||
UUID: database.ICA.UUID,
|
||||
Host: database.ICA.Host,
|
||||
Modeltype: database.ICA.Modeltype,
|
||||
Type: database.ICA.Type,
|
||||
Name: database.ICA.Name,
|
||||
Category: database.ICA.Category,
|
||||
State: database.ICA.State,
|
||||
Properties: database.ICA.Properties,
|
||||
}
|
||||
|
@ -238,7 +246,9 @@ func TestUpdateICAsUser(t *testing.T) {
|
|||
newIC := ICRequest{
|
||||
UUID: database.ICA.UUID,
|
||||
Host: database.ICA.Host,
|
||||
Modeltype: database.ICA.Modeltype,
|
||||
Type: database.ICA.Type,
|
||||
Name: database.ICA.Name,
|
||||
Category: database.ICA.Category,
|
||||
State: database.ICA.State,
|
||||
Properties: database.ICA.Properties,
|
||||
}
|
||||
|
@ -280,7 +290,9 @@ func TestDeleteICAsAdmin(t *testing.T) {
|
|||
newIC := ICRequest{
|
||||
UUID: database.ICA.UUID,
|
||||
Host: database.ICA.Host,
|
||||
Modeltype: database.ICA.Modeltype,
|
||||
Type: database.ICA.Type,
|
||||
Name: database.ICA.Name,
|
||||
Category: database.ICA.Category,
|
||||
State: database.ICA.State,
|
||||
Properties: database.ICA.Properties,
|
||||
}
|
||||
|
@ -330,7 +342,9 @@ func TestDeleteICAsUser(t *testing.T) {
|
|||
newIC := ICRequest{
|
||||
UUID: database.ICA.UUID,
|
||||
Host: database.ICA.Host,
|
||||
Modeltype: database.ICA.Modeltype,
|
||||
Type: database.ICA.Type,
|
||||
Name: database.ICA.Name,
|
||||
Category: database.ICA.Category,
|
||||
State: database.ICA.State,
|
||||
Properties: database.ICA.Properties,
|
||||
}
|
||||
|
@ -376,7 +390,9 @@ func TestGetAllICs(t *testing.T) {
|
|||
newICA := ICRequest{
|
||||
UUID: database.ICA.UUID,
|
||||
Host: database.ICA.Host,
|
||||
Modeltype: database.ICA.Modeltype,
|
||||
Type: database.ICA.Type,
|
||||
Name: database.ICA.Name,
|
||||
Category: database.ICA.Category,
|
||||
State: database.ICA.State,
|
||||
Properties: database.ICA.Properties,
|
||||
}
|
||||
|
@ -389,7 +405,9 @@ func TestGetAllICs(t *testing.T) {
|
|||
newICB := ICRequest{
|
||||
UUID: database.ICB.UUID,
|
||||
Host: database.ICB.Host,
|
||||
Modeltype: database.ICB.Modeltype,
|
||||
Type: database.ICB.Type,
|
||||
Name: database.ICB.Name,
|
||||
Category: database.ICB.Category,
|
||||
State: database.ICB.State,
|
||||
Properties: database.ICB.Properties,
|
||||
}
|
||||
|
@ -432,7 +450,9 @@ func TestGetConfigsOfIC(t *testing.T) {
|
|||
newICA := ICRequest{
|
||||
UUID: database.ICA.UUID,
|
||||
Host: database.ICA.Host,
|
||||
Modeltype: database.ICA.Modeltype,
|
||||
Type: database.ICA.Type,
|
||||
Name: database.ICA.Name,
|
||||
Category: database.ICA.Category,
|
||||
State: database.ICA.State,
|
||||
Properties: database.ICA.Properties,
|
||||
}
|
||||
|
|
|
@ -33,15 +33,19 @@ var validate *validator.Validate
|
|||
type validNewIC struct {
|
||||
UUID string `form:"UUID" validate:"required"`
|
||||
Host string `form:"Host" validate:"required"`
|
||||
Modeltype string `form:"Modeltype" validate:"required"`
|
||||
Properties postgres.Jsonb `form:"Properties" validate:"required"`
|
||||
State string `form:"State"`
|
||||
Type string `form:"Type" validate:"required"`
|
||||
Name string `form:"Name" validate:"required"`
|
||||
Category string `form:"Category" validate:"required"`
|
||||
Properties postgres.Jsonb `form:"Properties" validate:"omitempty"`
|
||||
State string `form:"State" validate:"omitempty"`
|
||||
}
|
||||
|
||||
type validUpdatedIC struct {
|
||||
UUID string `form:"UUID" validate:"omitempty"`
|
||||
Host string `form:"Host" validate:"omitempty"`
|
||||
Modeltype string `form:"Modeltype" validate:"omitempty"`
|
||||
Type string `form:"Type" validate:"omitempty"`
|
||||
Name string `form:"Name" validate:"omitempty"`
|
||||
Category string `form:"Category" validate:"omitempty"`
|
||||
Properties postgres.Jsonb `form:"Properties" validate:"omitempty"`
|
||||
State string `form:"State" validate:"omitempty"`
|
||||
}
|
||||
|
@ -71,7 +75,9 @@ func (r *addICRequest) createIC() InfrastructureComponent {
|
|||
|
||||
s.UUID = r.InfrastructureComponent.UUID
|
||||
s.Host = r.InfrastructureComponent.Host
|
||||
s.Modeltype = r.InfrastructureComponent.Modeltype
|
||||
s.Type = r.InfrastructureComponent.Type
|
||||
s.Name = r.InfrastructureComponent.Name
|
||||
s.Category = r.InfrastructureComponent.Category
|
||||
s.Properties = r.InfrastructureComponent.Properties
|
||||
if r.InfrastructureComponent.State != "" {
|
||||
s.State = r.InfrastructureComponent.State
|
||||
|
@ -91,8 +97,16 @@ func (r *updateICRequest) updatedIC(oldIC InfrastructureComponent) Infrastructur
|
|||
s.Host = r.InfrastructureComponent.Host
|
||||
}
|
||||
|
||||
if r.InfrastructureComponent.Modeltype != "" {
|
||||
s.Modeltype = r.InfrastructureComponent.Modeltype
|
||||
if r.InfrastructureComponent.Type != "" {
|
||||
s.Type = r.InfrastructureComponent.Type
|
||||
}
|
||||
|
||||
if r.InfrastructureComponent.Name != "" {
|
||||
s.Name = r.InfrastructureComponent.Name
|
||||
}
|
||||
|
||||
if r.InfrastructureComponent.Category != "" {
|
||||
s.Category = r.InfrastructureComponent.Category
|
||||
}
|
||||
|
||||
if r.InfrastructureComponent.State != "" {
|
||||
|
|
|
@ -57,7 +57,9 @@ type ConfigRequest struct {
|
|||
type ICRequest struct {
|
||||
UUID string `json:"uuid,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Modeltype string `json:"modelType,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Properties postgres.Jsonb `json:"properties,omitempty"`
|
||||
}
|
||||
|
@ -78,7 +80,9 @@ func addScenarioAndICAndConfig() (scenarioID uint, ICID uint, configID uint) {
|
|||
newICA := ICRequest{
|
||||
UUID: database.ICA.UUID,
|
||||
Host: database.ICA.Host,
|
||||
Modeltype: database.ICA.Modeltype,
|
||||
Type: database.ICA.Type,
|
||||
Name: database.ICA.Name,
|
||||
Category: database.ICA.Category,
|
||||
State: database.ICA.State,
|
||||
Properties: database.ICA.Properties,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue