From 4a58143a6e3c2427804467f1a05c161dba1679bf Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Fri, 20 Mar 2020 12:21:02 +0100 Subject: [PATCH] modify model of infrastructure component; add name, type, and category as top level parameters; fix testing of packages accordingly --- amqp/amqpclient.go | 2 +- database/database_test.go | 2 +- database/models.go | 8 +++- database/testdata.go | 16 +++++--- doc/api/docs.go | 6 +-- routes/component-configuration/config_test.go | 12 ++++-- routes/file/file_test.go | 8 +++- routes/infrastructure-component/ic_test.go | 40 ++++++++++++++----- .../infrastructure-component/ic_validators.go | 28 +++++++++---- routes/signal/signal_test.go | 8 +++- 10 files changed, 93 insertions(+), 37 deletions(-) diff --git a/amqp/amqpclient.go b/amqp/amqpclient.go index 374d4d5..3618ced 100644 --- a/amqp/amqpclient.go +++ b/amqp/amqpclient.go @@ -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(), diff --git a/database/database_test.go b/database/database_test.go index b4ad508..5fd360b 100644 --- a/database/database_test.go +++ b/database/database_test.go @@ -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 diff --git a/database/models.go b/database/models.go index 5eed608..bfd1844 100644 --- a/database/models.go +++ b/database/models.go @@ -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 diff --git a/database/testdata.go b/database/testdata.go index 9cf3841..f77f684 100644 --- a/database/testdata.go +++ b/database/testdata.go @@ -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(), diff --git a/doc/api/docs.go b/doc/api/docs.go index 65c9efa..6a987b9 100644 --- a/doc/api/docs.go +++ b/doc/api/docs.go @@ -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": { diff --git a/routes/component-configuration/config_test.go b/routes/component-configuration/config_test.go index e7f9c77..cb252e2 100644 --- a/routes/component-configuration/config_test.go +++ b/routes/component-configuration/config_test.go @@ -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, } diff --git a/routes/file/file_test.go b/routes/file/file_test.go index 30c3a5b..d47ee93 100644 --- a/routes/file/file_test.go +++ b/routes/file/file_test.go @@ -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, } diff --git a/routes/infrastructure-component/ic_test.go b/routes/infrastructure-component/ic_test.go index d303c84..fe53081 100644 --- a/routes/infrastructure-component/ic_test.go +++ b/routes/infrastructure-component/ic_test.go @@ -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, } diff --git a/routes/infrastructure-component/ic_validators.go b/routes/infrastructure-component/ic_validators.go index c901eba..dee0b78 100644 --- a/routes/infrastructure-component/ic_validators.go +++ b/routes/infrastructure-component/ic_validators.go @@ -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 != "" { diff --git a/routes/signal/signal_test.go b/routes/signal/signal_test.go index 48546c8..1cf2f58 100644 --- a/routes/signal/signal_test.go +++ b/routes/signal/signal_test.go @@ -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, }